1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkAbstractMapper3D.cxx
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 #include "vtkAbstractMapper3D.h"
16 #include "vtkDataSet.h"
17 #include "vtkMath.h"
18 #include "vtkMatrix4x4.h"
19 #include "vtkPlaneCollection.h"
20 
21 
22 // Construct with initial range (0,1).
vtkAbstractMapper3D()23 vtkAbstractMapper3D::vtkAbstractMapper3D()
24 {
25   vtkMath::UninitializeBounds(this->Bounds);
26   this->Center[0] = this->Center[1] = this->Center[2] = 0.0;
27 }
28 
29 // Get the bounds for this Prop as (Xmin,Xmax,Ymin,Ymax,Zmin,Zmax).
GetBounds(double bounds[6])30 void vtkAbstractMapper3D::GetBounds(double bounds[6])
31 {
32   this->GetBounds();
33   for (int i=0; i<6; i++)
34   {
35     bounds[i] = this->Bounds[i];
36   }
37 }
38 
GetCenter()39 double *vtkAbstractMapper3D::GetCenter()
40 {
41   this->GetBounds();
42   for (int i=0; i<3; i++)
43   {
44     this->Center[i] = (this->Bounds[2*i+1] + this->Bounds[2*i]) / 2.0;
45   }
46   return this->Center;
47 }
48 
GetLength()49 double vtkAbstractMapper3D::GetLength()
50 {
51   double diff, l=0.0;
52   int i;
53 
54   this->GetBounds();
55   for (i=0; i<3; i++)
56   {
57     diff = this->Bounds[2*i+1] - this->Bounds[2*i];
58     l += diff * diff;
59   }
60 
61   return sqrt(l);
62 }
63 
GetClippingPlaneInDataCoords(vtkMatrix4x4 * propMatrix,int i,double hnormal[4])64 void vtkAbstractMapper3D::GetClippingPlaneInDataCoords(
65   vtkMatrix4x4 *propMatrix, int i, double hnormal[4])
66 {
67   vtkPlaneCollection *clipPlanes = this->ClippingPlanes;
68   const double *mat = *propMatrix->Element;
69 
70   if (clipPlanes)
71   {
72     int n = clipPlanes->GetNumberOfItems();
73     if (i >= 0 && i < n)
74     {
75       // Get the plane
76       vtkPlane *plane = clipPlanes->GetItem(i);
77       double *normal = plane->GetNormal();
78       double *origin = plane->GetOrigin();
79 
80       // Compute the plane equation
81       double v1 = normal[0];
82       double v2 = normal[1];
83       double v3 = normal[2];
84       double v4 = -(v1*origin[0] + v2*origin[1] + v3*origin[2]);
85 
86       // Transform normal from world to data coords
87       hnormal[0] = v1*mat[0] + v2*mat[4] + v3*mat[8]  + v4*mat[12];
88       hnormal[1] = v1*mat[1] + v2*mat[5] + v3*mat[9]  + v4*mat[13];
89       hnormal[2] = v1*mat[2] + v2*mat[6] + v3*mat[10] + v4*mat[14];
90       hnormal[3] = v1*mat[3] + v2*mat[7] + v3*mat[11] + v4*mat[15];
91 
92       return;
93     }
94   }
95 
96   vtkErrorMacro("Clipping plane index " << i << " is out of range.");
97 }
98 
PrintSelf(ostream & os,vtkIndent indent)99 void vtkAbstractMapper3D::PrintSelf(ostream& os, vtkIndent indent)
100 {
101   this->Superclass::PrintSelf(os,indent);
102 }
103