avtViewInfo.C 9.9 KB
Newer Older
hrchilds's avatar
hrchilds committed
1 2
/*****************************************************************************
*
brugger's avatar
 
brugger committed
3
* Copyright (c) 2000 - 2012, Lawrence Livermore National Security, LLC
hrchilds's avatar
hrchilds committed
4
* Produced at the Lawrence Livermore National Laboratory
brugger's avatar
 
brugger committed
5
* LLNL-CODE-442911
hrchilds's avatar
hrchilds committed
6 7
* All rights reserved.
*
brugger's avatar
 
brugger committed
8
* This file is  part of VisIt. For  details, see https://visit.llnl.gov/.  The
hrchilds's avatar
hrchilds committed
9 10 11 12 13 14 15 16 17 18
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution  and  use  in  source  and  binary  forms,  with  or  without
* modification, are permitted provided that the following conditions are met:
*
*  - Redistributions of  source code must  retain the above  copyright notice,
*    this list of conditions and the disclaimer below.
*  - Redistributions in binary form must reproduce the above copyright notice,
*    this  list of  conditions  and  the  disclaimer (as noted below)  in  the
brugger's avatar
 
brugger committed
19 20 21
*    documentation and/or other materials provided with the distribution.
*  - Neither the name of  the LLNS/LLNL nor the names of  its contributors may
*    be used to endorse or promote products derived from this software without
hrchilds's avatar
hrchilds committed
22 23 24 25 26
*    specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT  HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR  IMPLIED WARRANTIES, INCLUDING,  BUT NOT  LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND  FITNESS FOR A PARTICULAR  PURPOSE
brugger's avatar
 
brugger committed
27 28 29
* ARE  DISCLAIMED. IN  NO EVENT  SHALL LAWRENCE  LIVERMORE NATIONAL  SECURITY,
* LLC, THE  U.S.  DEPARTMENT OF  ENERGY  OR  CONTRIBUTORS BE  LIABLE  FOR  ANY
* DIRECT,  INDIRECT,   INCIDENTAL,   SPECIAL,   EXEMPLARY,  OR   CONSEQUENTIAL
hrchilds's avatar
hrchilds committed
30 31 32 33 34 35 36 37 38
* DAMAGES (INCLUDING, BUT NOT  LIMITED TO, PROCUREMENT OF  SUBSTITUTE GOODS OR
* SERVICES; LOSS OF  USE, DATA, OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER
* CAUSED  AND  ON  ANY  THEORY  OF  LIABILITY,  WHETHER  IN  CONTRACT,  STRICT
* LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY  WAY
* OUT OF THE  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/

hrchilds's avatar
hrchilds committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
// ************************************************************************* //
//                               avtViewInfo.C                               //
// ************************************************************************* //

#include <avtViewInfo.h>

#include <vtkCamera.h>


// ****************************************************************************
//  Method: avtViewInfo constructor
//
//  Programmer: Hank Childs
//  Creation:   June 18, 2001
//
// ****************************************************************************

avtViewInfo::avtViewInfo()
{
    SetToDefault();
}


// ****************************************************************************
//  Method: avtViewInfo operator =
//
//  Arguments:
//    vi      The view info to copy.
//
//  Programmer: Hank Childs
//  Creation:   November 27, 2000
//
hrchilds's avatar
hrchilds committed
71 72 73 74
//  Modifications:
//    Eric Brugger, Fri Jun  6 15:30:49 PDT 2003
//    I added image pan and image zoom.
//
hrchilds's avatar
hrchilds committed
75 76 77
//    Hank Childs, Wed Oct 15 13:09:03 PDT 2003
//    Added eye angle.
//
78 79 80
//    Jeremy Meredith, Mon Aug  2 13:47:52 EDT 2010
//    Added shear.
//
hrchilds's avatar
hrchilds committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
// ****************************************************************************

avtViewInfo &
avtViewInfo::operator=(const avtViewInfo &vi)
{
    camera[0]    = vi.camera[0];
    camera[1]    = vi.camera[1];
    camera[2]    = vi.camera[2];
    focus[0]     = vi.focus[0];
    focus[1]     = vi.focus[1];
    focus[2]     = vi.focus[2];
    viewUp[0]    = vi.viewUp[0];
    viewUp[1]    = vi.viewUp[1];
    viewUp[2]    = vi.viewUp[2];
    viewAngle    = vi.viewAngle;
hrchilds's avatar
hrchilds committed
96
    eyeAngle     = vi.eyeAngle;
hrchilds's avatar
hrchilds committed
97 98 99 100 101
    parallelScale= vi.parallelScale;
    setScale     = vi.setScale;
    orthographic = vi.orthographic;
    nearPlane    = vi.nearPlane;
    farPlane     = vi.farPlane;
hrchilds's avatar
hrchilds committed
102 103 104
    imagePan[0]  = vi.imagePan[0];
    imagePan[1]  = vi.imagePan[1];
    imageZoom    = vi.imageZoom;
105 106 107
    shear[0]     = vi.shear[0];
    shear[1]     = vi.shear[1];
    shear[2]     = vi.shear[2];
hrchilds's avatar
hrchilds committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121

    return *this;
}


// ****************************************************************************
//  Method: avtViewInfo operator ==
//
//  Arguments:
//    vi      The view info to compare to.
//
//  Programmer: Hank Childs
//  Creation:   November 27, 2000
//
hrchilds's avatar
hrchilds committed
122 123 124 125
//  Modifications:
//    Eric Brugger, Fri Jun  6 15:30:49 PDT 2003
//    I added image pan and image zoom.
//
hrchilds's avatar
hrchilds committed
126 127 128
//    Hank Childs, Wed Oct 15 13:09:03 PDT 2003
//    Added eye angle.
//
129 130 131
//    Jeremy Meredith, Mon Aug  2 13:47:52 EDT 2010
//    Added shear.
//
hrchilds's avatar
hrchilds committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
// ****************************************************************************

bool
avtViewInfo::operator==(const avtViewInfo &vi)
{
    if (camera[0] != vi.camera[0] || camera[1] != vi.camera[1]
        || camera[2] != vi.camera[2])
    {
        return false;
    }

    if (focus[0] != vi.focus[0] || focus[1] != vi.focus[1]
        || focus[2] != vi.focus[2])
    {
        return false;
    }

    if (viewUp[0] != vi.viewUp[0] || viewUp[1] != vi.viewUp[1]
        || viewUp[2] != vi.viewUp[2])
    {
        return false;
    }

    if (viewAngle != vi.viewAngle)
    {
        return false;
    }

hrchilds's avatar
hrchilds committed
160 161 162 163 164
    if (eyeAngle != vi.eyeAngle)
    {
        return false;
    }

hrchilds's avatar
hrchilds committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
    if (setScale != vi.setScale || parallelScale != vi.parallelScale)
    {
        return false;
    }

    if (orthographic != vi.orthographic)
    {
        return false;
    }

    if (nearPlane != vi.nearPlane || farPlane != vi.farPlane)
    {
        return false;
    }

hrchilds's avatar
hrchilds committed
180 181
    if (imagePan[0] != vi.imagePan[0] || imagePan[1] != vi.imagePan[1] ||
        imageZoom != vi.imageZoom)
hrchilds's avatar
hrchilds committed
182 183 184
    {
        return false;
    }
hrchilds's avatar
hrchilds committed
185

186 187 188 189 190 191 192
    if (shear[0] != vi.shear[0] || shear[1] != vi.shear[1]
        || shear[2] != vi.shear[2])
    {
        return false;
    }


hrchilds's avatar
hrchilds committed
193 194 195 196 197 198 199 200 201 202 203 204 205
    return true;
}


// ****************************************************************************
//  Method: avtViewInfo::SetToDefault
//
//  Purpose:
//    Sets up with default values.
//
//  Programmer:  Kathleen Bonnell
//  Creation:    January 08, 2001
//
hrchilds's avatar
hrchilds committed
206 207 208 209
//  Modifications:
//    Eric Brugger, Fri Jun  6 15:30:49 PDT 2003
//    I added image pan and image zoom.
//
hrchilds's avatar
hrchilds committed
210 211 212
//    Hank Childs, Wed Oct 15 13:09:03 PDT 2003
//    Added eye angle.
//
213 214 215
//    Jeremy Meredith, Mon Aug  2 14:23:08 EDT 2010
//    Add shear for oblique projection support.
//
hrchilds's avatar
hrchilds committed
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
// ****************************************************************************

void
avtViewInfo::SetToDefault()
{
    camera[0]    =  0.;
    camera[1]    =  0.;
    camera[2]    = -1.;
    focus[0]     =  0.;
    focus[1]     =  0.;
    focus[2]     =  0.;
    viewUp[0]    =  0.;
    viewUp[1]    =  1.;
    viewUp[2]    =  0.;
    viewAngle    = 30.;
hrchilds's avatar
hrchilds committed
231
    eyeAngle     = 2.;
hrchilds's avatar
hrchilds committed
232 233 234 235 236
    setScale     = false;
    parallelScale= 1.;
    nearPlane    = 0.001;
    farPlane     = 100;
    orthographic = true;
hrchilds's avatar
hrchilds committed
237 238 239
    imagePan[0]  = 0.;
    imagePan[1]  = 0.;
    imageZoom    = 1.;
240 241 242
    shear[0]     =  0.;
    shear[1]     =  0.;
    shear[2]     =  1.;
hrchilds's avatar
hrchilds committed
243 244 245 246 247 248 249 250 251 252 253
}

// ****************************************************************************
//  Method: avtViewInfo::SetViewFromCamera
//
//  Arguments:
//    vtkcam      The camera from which to set the info.
//
//  Programmer:  Kathleen Bonnell
//  Creation:    January 04, 2001
//
hrchilds's avatar
hrchilds committed
254 255 256 257 258
//  Modifications:
//
//    Hank Childs, Wed Oct 15 13:09:03 PDT 2003
//    Added eye angle.
//
259 260 261
//    Jeremy Meredith, Mon Aug  2 14:23:08 EDT 2010
//    Add shear for oblique projection support.
//
hrchilds's avatar
hrchilds committed
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
// ****************************************************************************

void
avtViewInfo::SetViewFromCamera(vtkCamera *vtkcam)
{
    vtkcam->GetPosition(camera);
    vtkcam->GetFocalPoint(focus);
    vtkcam->GetViewUp(viewUp);

    double clipRange[2];
    vtkcam->GetClippingRange(clipRange);
    nearPlane = clipRange[0];
    farPlane  = clipRange[1];

    viewAngle = vtkcam->GetViewAngle();
hrchilds's avatar
hrchilds committed
277
    eyeAngle  = vtkcam->GetEyeAngle();
hrchilds's avatar
hrchilds committed
278 279
    parallelScale = vtkcam->GetParallelScale();
    orthographic = (vtkcam->GetParallelProjection() != 0 ? true : false);
280
    vtkcam->GetViewShear(shear);
hrchilds's avatar
hrchilds committed
281 282 283 284 285 286 287 288 289 290 291 292
}


// ****************************************************************************
//  Method: avtViewInfo::SetCameraFromView
//
//  Arguments:
//    vtkcam      The camera in which to store the view info. 
//
//  Programmer:  Kathleen Bonnell
//  Creation:    January 08, 2001
//
hrchilds's avatar
hrchilds committed
293 294 295 296
//  Modifications:
//    Eric Brugger, Fri Jun  6 15:30:49 PDT 2003
//    I added image pan and image zoom.
//
hrchilds's avatar
hrchilds committed
297 298 299 300
//    Eric Brugger, Wed Jun 18 17:46:36 PDT 2003 
//    I modified the call to SetWindowCenter since the meaning of its
//    arguments changed.
//
hrchilds's avatar
hrchilds committed
301 302 303
//    Hank Childs, Wed Oct 15 13:09:03 PDT 2003
//    Added eye angle.
//
304 305 306
//    Jeremy Meredith, Mon Aug  2 14:23:08 EDT 2010
//    Add shear for oblique projection support.
//
307 308 309 310
//    Kathleen Bonnell, Wed Jun  8 14:17:36 PDT 2011
//    Set user transform matrix when zooming (used to be done by hack inside
//    vtkCamera).
//
hrchilds's avatar
hrchilds committed
311
// ****************************************************************************
312 313
#include<vtkMatrix4x4.h>
#include<vtkTransform.h>
hrchilds's avatar
hrchilds committed
314 315 316 317 318

void
avtViewInfo::SetCameraFromView(vtkCamera *vtkcam) const
{
    vtkcam->SetViewAngle(viewAngle);
hrchilds's avatar
hrchilds committed
319
    vtkcam->SetEyeAngle(eyeAngle);
hrchilds's avatar
hrchilds committed
320 321 322 323 324 325
    if (setScale)
    {
        vtkcam->SetParallelScale(parallelScale);
    }
    vtkcam->SetParallelProjection(orthographic ? 1 : 0);
    vtkcam->SetClippingRange(nearPlane, farPlane);
326
    vtkcam->SetViewShear(shear[0],shear[1],shear[2]);
hrchilds's avatar
hrchilds committed
327 328 329
    vtkcam->SetFocalPoint(focus);
    vtkcam->SetPosition(camera);
    vtkcam->SetViewUp(viewUp);
hrchilds's avatar
hrchilds committed
330
    vtkcam->SetWindowCenter(2.0*imagePan[0], 2.0*imagePan[1]);
hrchilds's avatar
hrchilds committed
331
    vtkcam->SetFocalDisk(imageZoom);
332 333 334 335 336 337 338 339 340 341
    if (imageZoom != 1.0)
    {
        double matrix[4][4];
        vtkMatrix4x4::Identity(*matrix);
 
        matrix[0][0] = imageZoom;
        matrix[1][1] = imageZoom;
        vtkTransform *trans = vtkTransform::New();
        trans->SetMatrix(*matrix); 
        vtkcam->SetUserTransform(trans);
allens's avatar
allens committed
342
        trans->Delete();
343 344 345 346 347
    }
    else
    {
        vtkcam->SetUserTransform(NULL);
    }
hrchilds's avatar
hrchilds committed
348
}