1 // GEOM OBJECT : interactive object for Geometry entities visualization
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : GEOM_Actor.cxx
25 // Author : Christophe ATTANASIO
30 \class GEOM_Actor GEOM_Actor.h
31 \brief This class allows to display an OpenCASCADE CAD model in a VTK viewer.
33 #include "GEOM_Actor.h"
35 #include "GEOM_DeviceActor.h"
36 #include "GEOM_VertexSource.h"
37 #include "GEOM_EdgeSource.h"
38 #include "GEOM_WireframeFace.h"
39 #include "GEOM_ShadingFace.h"
40 #include "SVTK_Actor.h"
42 #include <vtkObjectFactory.h>
43 #include <vtkRenderer.h>
44 #include <vtkProperty.h>
45 #include <vtkPointPicker.h>
46 #include <vtkCellPicker.h>
48 #include <TopAbs_ShapeEnum.hxx>
49 #include <TopExp_Explorer.hxx>
50 #include <Poly_Triangulation.hxx>
51 #include <BRepMesh_IncrementalMesh.hxx>
52 #include <Bnd_Box.hxx>
54 #include <BRep_Tool.hxx>
55 #include <BRepBndLib.hxx>
56 #include <TopTools_ListOfShape.hxx>
57 #include <TopoDS_Iterator.hxx>
60 #include <vtkPolyDataWriter.h>
62 #include <vtkAppendPolyData.h>
63 #include <vtkPolyDataMapper.h>
64 #include <vtkPolyData.h>
65 #include <vtkTransform.h>
66 #include <vtkMatrix4x4.h>
68 #include <vtkCamera.h>
70 //vtkStandardNewMacro(GEOM_Actor);
76 GEOM_Actor::GEOM_Actor():
77 // myDisplayMode(eWireframe),
80 myVertexActor(GEOM_DeviceActor::New(),true),
81 myVertexSource(GEOM_VertexSource::New(),true),
83 myIsolatedEdgeActor(GEOM_DeviceActor::New(),true),
84 myIsolatedEdgeSource(GEOM_EdgeSource::New(),true),
86 myOneFaceEdgeActor(GEOM_DeviceActor::New(),true),
87 myOneFaceEdgeSource(GEOM_EdgeSource::New(),true),
89 mySharedEdgeActor(GEOM_DeviceActor::New(),true),
90 mySharedEdgeSource(GEOM_EdgeSource::New(),true),
92 myWireframeFaceActor(GEOM_DeviceActor::New(),true),
93 myWireframeFaceSource(GEOM_WireframeFace::New(),true),
95 myShadingFaceActor(GEOM_DeviceActor::New(),true),
96 myShadingFaceSource(GEOM_ShadingFace::New(),true),
98 myHighlightActor(GEOM_DeviceActor::New(),true),
99 myAppendFilter(vtkAppendPolyData::New(),true),
100 myPolyDataMapper(vtkPolyDataMapper::New(),true),
102 myHighlightProp(vtkProperty::New()),
103 myPreHighlightProp(vtkProperty::New()),
104 myShadingFaceProp(vtkProperty::New())
108 cout <<this<< " GEOM_Actor::GEOM_Actor"<<endl;
111 myPolyDataMapper->SetInput(myAppendFilter->GetOutput());
112 vtkProperty* aProperty;
114 myHighlightProp->SetAmbient(0.5);
115 myHighlightProp->SetDiffuse(0.3);
116 myHighlightProp->SetSpecular(0.2);
117 myHighlightProp->SetRepresentationToSurface();
118 myHighlightProp->SetAmbientColor(1, 1, 1);
119 myHighlightProp->SetDiffuseColor(1, 1, 1);
120 myHighlightProp->SetSpecularColor(0.5, 0.5, 0.5);
121 myHighlightActor->SetProperty(myHighlightProp.GetPointer());
123 this->myHighlightActor->SetInput(myAppendFilter->GetOutput(),false);
125 myPreHighlightProp->SetColor(0,1,1);
126 myPreHighlightProp->SetPointSize(SALOME_POINT_SIZE+2);
127 myPreHighlightProp->SetLineWidth(SALOME_LINE_WIDTH+1);
128 myPreHighlightProp->SetRepresentationToWireframe();
130 myAppendFilter->AddInput(myVertexSource->GetOutput());
131 myVertexActor->SetInput(myVertexSource->GetOutput(),false);
132 aProperty = myVertexActor->GetProperty();
133 aProperty->SetRepresentation(VTK_POINTS);
134 aProperty->SetPointSize(3);
135 aProperty->SetColor(1, 1, 0);
137 myAppendFilter->AddInput(myIsolatedEdgeSource->GetOutput());
138 myIsolatedEdgeActor->SetInput(myIsolatedEdgeSource->GetOutput(),false);
139 aProperty = myIsolatedEdgeActor->GetProperty();
140 aProperty->SetRepresentation(VTK_WIREFRAME);
141 aProperty->SetColor(1, 0, 0);
143 myAppendFilter->AddInput(myOneFaceEdgeSource->GetOutput());
144 myOneFaceEdgeActor->SetInput(myOneFaceEdgeSource->GetOutput(),false);
145 aProperty = myOneFaceEdgeActor->GetProperty();
146 aProperty->SetRepresentation(VTK_WIREFRAME);
147 aProperty->SetColor(0, 1, 0);
149 myAppendFilter->AddInput(mySharedEdgeSource->GetOutput());
150 mySharedEdgeActor->SetInput(mySharedEdgeSource->GetOutput(),false);
151 aProperty = mySharedEdgeActor->GetProperty();
152 aProperty->SetRepresentation(VTK_WIREFRAME);
153 aProperty->SetColor(1, 1, 0);
155 myAppendFilter->AddInput(myWireframeFaceSource->GetOutput());
156 myWireframeFaceActor->SetInput(myWireframeFaceSource->GetOutput(),false);
157 aProperty = myWireframeFaceActor->GetProperty();
158 aProperty->SetRepresentation(VTK_WIREFRAME);
159 aProperty->SetColor(0.5, 0.5, 0.5);
161 myShadingFaceActor->SetInput(myShadingFaceSource->GetOutput(),true);
163 myShadingFaceProp->SetRepresentation(VTK_SURFACE);
164 myShadingFaceProp->SetInterpolationToGouraud();
165 myShadingFaceProp->SetAmbient(1.0);
166 myShadingFaceProp->SetDiffuse(1.0);
167 myShadingFaceProp->SetSpecular(0.4);
168 myShadingFaceProp->SetAmbientColor(0.329412, 0.223529, 0.027451);
169 myShadingFaceProp->SetDiffuseColor(0.780392, 0.568627, 0.113725);
170 myShadingFaceProp->SetSpecularColor(0.992157, 0.941176, 0.807843);
172 myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
174 // Toggle display mode
175 setDisplayMode(0); // WIRE FRAME
180 GEOM_Actor::~GEOM_Actor()
183 cout <<this<< " ~GEOM_Actor::GEOM_Actor"<<endl;
185 myHighlightProp->Delete();
186 myPreHighlightProp->Delete();
187 myShadingFaceProp->Delete();
194 GEOM_Actor* anObject = new GEOM_Actor();
195 anObject->SetMapper(anObject->myPolyDataMapper.Get());
200 void Write(vtkPolyData* theDataSet, const char* theFileName){
201 vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New();
202 cout<<"Write - "<<theFileName<<"' : "<<theDataSet->GetNumberOfPoints()<<"; "<<theDataSet->GetNumberOfCells()<<endl;
203 aWriter->SetInput(theDataSet);
204 aWriter->SetFileName(theFileName);
213 this->myVertexSource->Modified();
214 this->myIsolatedEdgeSource->Modified();
215 this->myOneFaceEdgeSource->Modified();
216 this->mySharedEdgeSource->Modified();
217 this->myWireframeFaceSource->Modified();
218 this->myShadingFaceSource->Modified();
223 SetMapper(vtkMapper* theMapper)
225 SALOME_Actor::SetMapper(theMapper);
230 AddToRender(vtkRenderer* theRenderer)
232 //SALOME_Actor::AddToRender(theRenderer);
234 theRenderer->AddActor(this);
236 this->myHighlightActor->AddToRender(theRenderer);
239 myShadingFaceActor->AddToRender(theRenderer);
240 myWireframeFaceActor->AddToRender(theRenderer);
242 mySharedEdgeActor->AddToRender(theRenderer);
243 myOneFaceEdgeActor->AddToRender(theRenderer);
244 myIsolatedEdgeActor->AddToRender(theRenderer);
246 myVertexActor->AddToRender(theRenderer);
251 RemoveFromRender(vtkRenderer* theRenderer)
253 //SALOME_Actor::RemoveFromRender(theRenderer);
256 theRenderer->RemoveActor(this);
258 myHighlightActor->RemoveFromRender(theRenderer);
259 myShadingFaceActor->RemoveFromRender(theRenderer);
260 myWireframeFaceActor->RemoveFromRender(theRenderer);
262 mySharedEdgeActor->RemoveFromRender(theRenderer);
263 myOneFaceEdgeActor->RemoveFromRender(theRenderer);
264 myIsolatedEdgeActor->RemoveFromRender(theRenderer);
266 myVertexActor->RemoveFromRender(theRenderer);
270 SetVisibility(false);
275 setDisplayMode(int theMode)
278 cout << "GEOM_Actor::SetDisplayMode = "<<theMode <<endl;
280 VTKViewer_Actor::setDisplayMode(theMode);
281 SetVisibility(GetVisibility());
286 SetSelected(bool theIsSelected)
289 cout << "GEOM_Actor::SetSelected = "<<theIsSelected <<endl;
292 myIsSelected = theIsSelected;
293 SetVisibility(GetVisibility());
298 SetVisibility(int theVisibility)
301 cout << "GEOM_Actor::SetVisibility = "<<theVisibility <<" myIsSelected="<< myIsSelected
302 << " theVisibility="<<theVisibility<<" myIsPreselected="<<myIsPreselected<<endl;
305 SALOME_Actor::SetVisibility(theVisibility);
307 this->myHighlightActor->SetVisibility(theVisibility && (myIsSelected || myIsPreselected));
309 myShadingFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eShading) && (!myIsSelected || !myIsPreselected));
310 myWireframeFaceActor->SetVisibility(theVisibility && (myDisplayMode ==(int)eWireframe) && !myIsSelected);
312 mySharedEdgeActor->SetVisibility(theVisibility && myDisplayMode == (int)eWireframe && !myIsSelected);
313 myOneFaceEdgeActor->SetVisibility(theVisibility && myDisplayMode == (int)eWireframe && !myIsSelected);
314 myIsolatedEdgeActor->SetVisibility(theVisibility && !myIsSelected);
316 myVertexActor->SetVisibility(false);// must be added new mode points
322 ::SetNbIsos(const int theNb[2])
324 myNbIsos[0] = theNb[0];
325 myNbIsos[1] = theNb[1];
330 ::GetNbIsos(int &theNbU,int &theNbV)
332 theNbU = myNbIsos[0];
333 theNbV = myNbIsos[1];
338 MeshShape(const TopoDS_Shape& theShape,
339 float& theDeflection,
342 static Standard_Real RELATIVE_DEFLECTION = 0.0001;
343 Standard_Real aDeflection = theDeflection;
345 if(theDeflection <= 0) { // Compute default theDeflection
347 BRepBndLib::Add(theShape, B);
348 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
349 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
350 Standard_Real aDiagonal = (aXmax-aXmin)*(aXmax-aXmin) +
351 (aYmax-aYmin)*(aYmax-aYmin) +
352 (aZmax-aZmin)*(aZmax-aZmin);
353 aDiagonal = sqrt(aDiagonal);
354 aDeflection = aDiagonal*RELATIVE_DEFLECTION;
357 theDeflection = RELATIVE_DEFLECTION;
359 theDeflection = aDeflection;
362 BRepMesh_IncrementalMesh aMesh(theShape,aDeflection);
367 SetDeflection(float theDeflection, bool theIsRelative)
369 myDeflection = theDeflection;
370 myIsRelative = theIsRelative;
372 MeshShape(myShape,myDeflection,myIsRelative);
377 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
384 myVertexSource->Clear();
385 myIsolatedEdgeSource->Clear();
386 myOneFaceEdgeSource->Clear();
387 mySharedEdgeSource->Clear();
388 myWireframeFaceSource->Clear();
389 myShadingFaceSource->Clear();
391 TopExp_Explorer aVertexExp (theShape,TopAbs_VERTEX);
392 for (; aVertexExp.More(); aVertexExp.Next())
394 const TopoDS_Vertex& aVertex = TopoDS::Vertex(aVertexExp.Current());
395 myVertexSource->AddVertex(aVertex);
397 SetDeflection(theDeflection, theIsRelative);
399 // look if edges are free or shared
400 TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
401 TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap);
403 SetShape(theShape,anEdgeMap,theIsVector);
406 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
407 const TopTools_IndexedDataMapOfShapeListOfShape& theEdgeMap,
410 if (theShape.ShapeType() == TopAbs_COMPOUND) {
411 TopoDS_Iterator anItr(theShape);
412 for (; anItr.More(); anItr.Next()) {
413 SetShape(anItr.Value(),theEdgeMap,theIsVector);
417 switch (theShape.ShapeType()) {
419 TopExp_Explorer anEdgeExp(theShape,TopAbs_EDGE);
420 for (; anEdgeExp.More(); anEdgeExp.Next()){
421 const TopoDS_Edge& anEdge = TopoDS::Edge(anEdgeExp.Current());
422 if (!BRep_Tool::Degenerated(anEdge))
423 myIsolatedEdgeSource->AddEdge(anEdge,theIsVector);
428 const TopoDS_Edge& anEdge = TopoDS::Edge(theShape);
429 if (!BRep_Tool::Degenerated(anEdge))
430 myIsolatedEdgeSource->AddEdge(anEdge,theIsVector);
433 case TopAbs_VERTEX: {
437 TopExp_Explorer aFaceExp (theShape,TopAbs_FACE);
438 for(; aFaceExp.More(); aFaceExp.Next()) {
439 const TopoDS_Face& aFace = TopoDS::Face(aFaceExp.Current());
440 myWireframeFaceSource->AddFace(aFace);
441 myShadingFaceSource->AddFace(aFace);
442 TopExp_Explorer anEdgeExp(aFaceExp.Current(), TopAbs_EDGE);
443 for(; anEdgeExp.More(); anEdgeExp.Next()) {
444 const TopoDS_Edge& anEdge = TopoDS::Edge(anEdgeExp.Current());
445 if(!BRep_Tool::Degenerated(anEdge)){
446 // compute the number of faces
447 int aNbOfFaces = theEdgeMap.FindFromKey(anEdge).Extent();
449 case 0: // isolated edge
450 myIsolatedEdgeSource->AddEdge(anEdge,theIsVector);
452 case 1: // edge in only one face
453 myOneFaceEdgeSource->AddEdge(anEdge,theIsVector);
455 default: // edge shared by at least two faces
456 mySharedEdgeSource->AddEdge(anEdge,theIsVector);
466 void GEOM_Actor::setDeflection(double adef) {
468 cout << "GEOM_Actor::setDeflection"<<endl;
470 SetDeflection((float)adef,GetIsRelative());
474 // warning! must be checked!
475 // SetHighlightProperty
476 // SetWireframeProperty
477 // SetShadingProperty
479 void GEOM_Actor::SetHighlightProperty(vtkProperty* Prop)
482 cout << "GEOM_Actor::SetHighlightProperty"<<endl;
484 this->myHighlightActor->GetProperty()->DeepCopy(Prop);
488 void GEOM_Actor::SetWireframeProperty(vtkProperty* Prop)
491 cout << this << " GEOM_Actor::SetWireframeProperty"<<endl;
494 myWireframeFaceActor->SetProperty(Prop);
497 void GEOM_Actor::SetShadingProperty(vtkProperty* Prop)
500 cout << "GEOM_Actor::SetShadingProperty"<<endl;
502 myShadingFaceProp->DeepCopy(Prop);
506 void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *theMapper)
509 cout << "GEOM_Actor::Render"<<endl;
515 /* render the property */
516 if (!this->Property) {
517 // force creation of a property
519 this->Property->SetInterpolation(1);
520 this->Property->SetRepresentationToSurface();
521 this->Property->SetAmbient(0.3);
522 this->Property->SetAmbientColor(0.88,0.86,0.2);
523 this->Property->SetDiffuseColor(0.99,0.7,0.21);
524 this->Property->SetSpecularColor(0.99,0.98,0.83);
527 switch(myDisplayMode){
529 myPreHighlightProp->SetRepresentationToWireframe();
530 myHighlightProp->SetRepresentationToWireframe();
533 myPreHighlightProp->SetRepresentationToSurface();
534 myHighlightProp->SetRepresentationToSurface();
540 this->myHighlightActor->SetProperty(myPreHighlightProp.GetPointer());
541 myShadingFaceActor->SetProperty(myPreHighlightProp.GetPointer());
543 this->myHighlightActor->SetProperty(myShadingFaceProp.GetPointer());
544 myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
548 this->myHighlightActor->SetProperty(myHighlightProp.GetPointer());
549 myShadingFaceActor->SetProperty(myHighlightProp.GetPointer());
552 this->Property->Render(this, ren);
553 if (this->BackfaceProperty) {
554 this->BackfaceProperty->BackfaceRender(this, ren);
555 this->Device->SetBackfaceProperty(this->BackfaceProperty);
557 this->Device->SetProperty(this->Property);
558 if(myShape.ShapeType() == TopAbs_VERTEX) {
560 //The parameter determine size of vertex actor relate to diagonal of RendererWindow
561 static vtkFloatingPointType delta = 0.01;
562 vtkFloatingPointType X1 = -1, Y1 = -1, Z1 = 0;
563 ren->ViewToWorld(X1,Y1,Z1);
564 vtkFloatingPointType X2 = +1, Y2 = +1, Z2 = 0;
565 ren->ViewToWorld(X2,Y2,Z2);
566 Z2 = sqrt((X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1) + (Z2-Z1)*(Z2-Z1));
567 this->SetScale(Z2*delta);
569 vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
570 this->GetMatrix(ren->GetActiveCamera(), aMatrix);
571 this->Device->SetUserMatrix(aMatrix);
572 this->Device->Render(ren,theMapper);
575 this->Device->Render(ren, theMapper);
579 void GEOM_Actor::ReleaseGraphicsResources(vtkWindow *)
582 cout << "GEOM_Actor::ReleaseGraphicsResources"<<endl;
588 void GEOM_Actor::ShallowCopy(vtkProp *prop)
591 cout << "GEOM_Actor::ShallowCopy"<<endl;
593 GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
596 this->SetShape(f->getTopo(),f->GetDeflection(),f->GetIsRelative());
600 this->SALOME_Actor::ShallowCopy(prop);
603 const TopoDS_Shape& GEOM_Actor::getTopo() {
605 cout << "GEOM_Actor::getTopo"<<endl;
610 void GEOM_Actor::setInputShape(const TopoDS_Shape& ashape, double adef1,
611 int imode, bool isVector)
614 cout << "GEOM_Actor::setInputShape"<<endl;
618 double GEOM_Actor::getDeflection()
621 cout << "GEOM_Actor::getDeflection"<<endl;
623 return (double) GetDeflection();
627 double GEOM_Actor::isVector()
630 cout << "GEOM_Actor::isVector"<<endl;
635 void GEOM_Actor::SubShapeOn()
638 cout << "GEOM_Actor::SubShapeOn"<<endl;
642 void GEOM_Actor::SubShapeOff()
645 cout << "GEOM_Actor::SubShapeOff"<<endl;
649 void GEOM_Actor::highlight(bool highlight)
652 cout << this << " GEOM_Actor::highlight highlight="<<highlight<<endl;
654 SALOME_Actor::highlight(highlight);
657 void GEOM_Actor::SetOpacity(vtkFloatingPointType opa)
660 myShadingFaceProp->SetOpacity(opa);
661 myHighlightProp->SetOpacity(opa);
662 myPreHighlightProp->SetOpacity(opa);
665 vtkFloatingPointType GEOM_Actor::GetOpacity()
668 return myShadingFaceProp->GetOpacity();
671 void GEOM_Actor::SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
674 myShadingFaceProp->SetColor(r,g,b);
677 void GEOM_Actor::GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b)
680 vtkFloatingPointType aRGB[3];
681 myShadingFaceProp->GetColor(aRGB);
687 bool GEOM_Actor::IsInfinite()
689 return (bool)(myShape.Infinite());
693 To map current selection to VTK representation
697 ::Highlight(bool theIsHighlight)
699 myIsSelected = theIsHighlight;
701 cout << this << " GEOM_Actor::Highlight myIsSelected="<<myIsSelected<<endl;
704 SALOME_Actor::Highlight(theIsHighlight); // this method call ::highlight(theIsHighlight) in the end
705 SetVisibility(GetVisibility());
709 To process prehighlight (called from SVTK_InteractorStyle)
713 ::PreHighlight(vtkInteractorStyle *theInteractorStyle,
714 SVTK_SelectionEvent* theSelectionEvent,
718 cout << this<<" GEOM_Actor::PreHighlight (3) theIsHighlight="<<theIsHighlight<<endl;
721 if ( !GetPickable() )
724 myPreHighlightActor->SetVisibility( false );
725 bool anIsPreselected = myIsPreselected;
727 Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
728 bool anIsChanged = (mySelectionMode != aSelectionMode);
730 if( !theIsHighlight ) {
731 SetPreSelected( false );
733 switch(aSelectionMode){
734 case ActorSelection :
736 if( !mySelector->IsSelected( myIO ) ) {
737 SetPreSelected( true );
745 mySelectionMode = aSelectionMode;
746 anIsChanged |= (anIsPreselected != myIsPreselected);
748 SetVisibility(GetVisibility());
753 To process highlight (called from SVTK_InteractorStyle)
757 ::Highlight(vtkInteractorStyle *theInteractorStyle,
758 SVTK_SelectionEvent* theSelectionEvent,
761 // define the selection of object
763 cout << endl << this << " GEOM_Actor::Highlight (3) myIsSelected="<<myIsSelected<<endl;
765 bool aRet = SALOME_Actor::Highlight(theInteractorStyle,theSelectionEvent,theIsHighlight);
766 SetSelected(theIsHighlight);
768 SetPreSelected(false);
774 // Copy the follower's composite 4x4 matrix into the matrix provided.
775 void GEOM_Actor::GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result)
778 double Rx[3], Ry[3], Rz[3], p1[3];
779 vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
783 this->GetOrientation();
784 this->Transform->Push();
785 this->Transform->PostMultiply();
786 this->Transform->Identity();
788 // apply user defined matrix last if there is one
789 if (this->UserMatrix)
791 this->Transform->Concatenate(this->UserMatrix);
794 this->Transform->Translate(-this->Origin[0],
798 this->Transform->Scale(this->Scale[0],
803 this->Transform->RotateY(this->Orientation[1]);
804 this->Transform->RotateX(this->Orientation[0]);
805 this->Transform->RotateZ(this->Orientation[2]);
811 pos = theCam->GetPosition();
812 vup = theCam->GetViewUp();
814 if (theCam->GetParallelProjection())
816 theCam->GetDirectionOfProjection(Rz);
821 (pos[0] - this->Position[0])*(pos[0] - this->Position[0]) +
822 (pos[1] - this->Position[1])*(pos[1] - this->Position[1]) +
823 (pos[2] - this->Position[2])*(pos[2] - this->Position[2]));
824 for (i = 0; i < 3; i++)
826 Rz[i] = (pos[i] - this->Position[i])/distance;
830 vtkMath::Cross(vup,Rz,Rx);
831 vtkMath::Normalize(Rx);
832 vtkMath::Cross(Rz,Rx,Ry);
834 matrix->Element[0][0] = Rx[0];
835 matrix->Element[1][0] = Rx[1];
836 matrix->Element[2][0] = Rx[2];
837 matrix->Element[0][1] = Ry[0];
838 matrix->Element[1][1] = Ry[1];
839 matrix->Element[2][1] = Ry[2];
840 matrix->Element[0][2] = Rz[0];
841 matrix->Element[1][2] = Rz[1];
842 matrix->Element[2][2] = Rz[2];
844 this->Transform->Concatenate(matrix);
847 // translate to projection reference point PRP
848 // this is the camera's position blasted through
849 // the current matrix
850 p1[0] = this->Origin[0] + this->Position[0];
851 p1[1] = this->Origin[1] + this->Position[1];
852 p1[2] = this->Origin[2] + this->Position[2];
854 this->Transform->Translate(p1[0],p1[1],p1[2]);
855 this->Transform->GetMatrix(result);
858 this->Transform->Pop();