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_VTKTrihedron.cxx
25 // Author : Sergey LITONIN
29 #include "GEOM_VTKTrihedron.hxx"
30 #include "utilities.h"
31 #include "GEOM_OCCReader.h"
33 #include <Geom_Axis2Placement.hxx>
37 #include <BRep_Builder.hxx>
38 #include <BRepBuilderAPI_MakeEdge.hxx>
39 #include <TopoDS_Edge.hxx>
40 #include <TopoDS_Compound.hxx>
43 #include <vtkMapper.h>
44 #include <vtkDataSet.h>
45 #include <vtkRenderer.h>
46 #include <vtkFollower.h>
47 #include <vtkRenderWindow.h>
48 #include <vtkObjectFactory.h>
49 #include <vtkPolyData.h>
51 #include <vtkProperty.h>
52 #include <vtkLineSource.h>
53 #include <vtkConeSource.h>
54 #include <vtkPolyDataMapper.h>
55 #include <vtkAppendPolyData.h>
56 #include <vtkMatrix4x4.h>
57 #include <vtkTransform.h>
58 #include <vtkVectorText.h>
61 Class : GEOM_VTKTrihedron
62 Description : Class for displaying axis of trihedron in VTK viewer.
63 Placement of trihedron is chahged with SetPlacement() method
65 class GEOM_VTKTrihedronAxis : public VTKViewer_Axis
69 GEOM_VTKTrihedronAxis();
70 GEOM_VTKTrihedronAxis( const GEOM_VTKTrihedronAxis& );
71 ~GEOM_VTKTrihedronAxis();
75 vtkTypeMacro( GEOM_VTKTrihedronAxis, VTKViewer_Axis );
76 static GEOM_VTKTrihedronAxis* New();
78 void SetAxis( const gp_Ax1& theAxis, const int theRot, vtkFloatingPointType theColor[ 3 ] );
79 virtual void Render( vtkRenderer* theRenderer );
80 virtual void SetSize( vtkFloatingPointType theSize );
81 gp_Pnt GetOri() const;
82 void SetColor( const vtkFloatingPointType theColor[ 3 ] );
86 vtkFloatingPointType myOri[ 3 ];
87 vtkMatrix4x4* myMatrix;
91 vtkStandardNewMacro( GEOM_VTKTrihedronAxis );
93 GEOM_VTKTrihedronAxis::GEOM_VTKTrihedronAxis()
95 vtkProperty* aProperty = vtkProperty::New();
96 aProperty->SetColor( 0.0, 0.0, 1.0 );
97 SetProperty( aProperty );
99 myMatrix = vtkMatrix4x4::New();
100 myTrsf = vtkTransform::New();
103 GEOM_VTKTrihedronAxis::~GEOM_VTKTrihedronAxis()
109 void GEOM_VTKTrihedronAxis::SetSize( vtkFloatingPointType theSize )
111 vtkFloatingPointType aPosition[ 3 ] = { myOri[ 0 ] + myDir[ 0 ] * theSize,
112 myOri[ 1 ] + myDir[ 1 ] * theSize,
113 myOri[ 2 ] + myDir[ 2 ] * theSize };
115 myLineSource->SetPoint1( myOri[ 0 ], myOri[ 1 ], myOri[ 2 ] );
116 myLineSource->SetPoint2( aPosition );
118 myArrowActor->SetPosition( 0, 0, 0 );
119 myArrowActor->SetOrientation( 0, 0, 0 );
120 myArrowActor->SetUserMatrix( 0 );
124 aTrsf.SetDisplacement( gp_Ax3( gp_Pnt( 0, 0, 0 ), gp_Dir( 1, 0, 0 ) ),
125 gp_Ax3( GetOri(), gp_Dir( myDir[ 0 ], myDir[ 1 ], myDir[ 2 ] ) ) );
127 const gp_XYZ& aTrans = aTrsf.TranslationPart();
128 gp_Mat aRot = aTrsf.VectorialPart();
130 for ( int i = 1; i <= 3; i++ )
131 for ( int j = 1; j <= 3; j++ )
132 myMatrix->SetElement( i - 1, j - 1, aRot( i, j ) );
134 myArrowActor->SetUserMatrix( myMatrix );
135 myArrowActor->SetPosition( aPosition );
137 myLabelActor->SetPosition( 0, 0, 0 );
138 myLabelActor->AddPosition( aPosition );
141 void GEOM_VTKTrihedronAxis::Render(vtkRenderer* theRenderer)
143 myLineActor->Render( theRenderer );
144 myArrowActor->Render( theRenderer );
145 myLabelActor->Render( theRenderer );
147 vtkCamera* aCamera = theRenderer->GetActiveCamera();
148 SetCamera( aCamera );
151 gp_Pnt GEOM_VTKTrihedronAxis::GetOri() const
153 return gp_Pnt( myOri[ 0 ], myOri[ 1 ], myOri[ 2 ] );
156 void GEOM_VTKTrihedronAxis::SetAxis( const gp_Ax1& theAxis,
158 vtkFloatingPointType theColor[ 3 ] )
160 gp_Pnt aLoc = theAxis.Location();
161 gp_Dir aDir = theAxis.Direction();
163 myOri[ 0 ] = aLoc.X();
164 myOri[ 1 ] = aLoc.Y();
165 myOri[ 2 ] = aLoc.Z();
167 myDir[ 0 ] = aDir.X();
168 myDir[ 1 ] = aDir.Y();
169 myDir[ 2 ] = aDir.Z();
171 vtkFloatingPointType aColor[ 3 ] = { 0, 0, 0 };
172 aColor[ theRot ] = 1;
173 vtkProperty* aProperty = vtkProperty::New();
174 if ( theColor[ 0 ] == -1 )
175 aProperty->SetColor( aColor[ 0 ], aColor[ 1 ], aColor[ 2 ] );
177 aProperty->SetColor( theColor[ 0 ], theColor[ 1 ], theColor[ 2 ] );
178 SetProperty( aProperty );
181 if ( theRot == 0 ) myVectorText->SetText( "X" );
182 else if ( theRot == 1 ) myVectorText->SetText( "Y" );
183 else if ( theRot == 2 ) myVectorText->SetText( "Z" );
186 void GEOM_VTKTrihedronAxis::SetColor( const vtkFloatingPointType theColor[ 3 ] )
188 vtkProperty* aProperty = vtkProperty::New();
189 aProperty->SetColor( theColor[ 0 ], theColor[ 1 ], theColor[ 2 ] );
190 SetProperty( aProperty );
196 Class : GEOM_VTKTrihedron
197 Description : Class for displaying trihedron of local CS in VTK viewer.
198 Placement of trihedron is chahged with SetPlacement() method
201 vtkStandardNewMacro( GEOM_VTKTrihedron );
203 GEOM_VTKTrihedron::GEOM_VTKTrihedron()
205 myMapper = vtkPolyDataMapper::New();
206 myAxis[ 0 ] = myAxis[ 1 ] = myAxis[ 2 ] = 0;
208 SetInfinitive( true );
209 myColor[ 0 ] = myColor[ 1 ] = myColor[ 1 ] = -1;
210 SetInfinitive( true );
213 GEOM_VTKTrihedron::~GEOM_VTKTrihedron()
215 for ( int i = 0; i < 3; i++ )
222 void GEOM_VTKTrihedron::SetSize( vtkFloatingPointType theSize )
225 for ( int i = 0; i < 3; i++ )
226 myAxis[i]->SetSize( theSize );
229 // Calculate new sensitive area
230 gp_Pnt anOri = ( (GEOM_VTKTrihedronAxis*)myAxis[ 0 ] )->GetOri();
231 gp_Pnt aEndX( myLocation.XYZ() + myDirX.XYZ() * mySize );
232 gp_Pnt aEndY( myLocation.XYZ() + myDirY.XYZ() * mySize );
233 gp_Pnt aEndZ( myLocation.XYZ() + myDirZ.XYZ() * mySize );
235 vtkLineSource* aSrcX = vtkLineSource::New();
236 vtkLineSource* aSrcY = vtkLineSource::New();
237 vtkLineSource* aSrcZ = vtkLineSource::New();
239 aSrcX->SetPoint1( anOri.X(), anOri.Y(), anOri.Z() );
240 aSrcX->SetPoint2( aEndX.X(), aEndX.Y(), aEndX.Z() );
242 aSrcY->SetPoint1( anOri.X(), anOri.Y(), anOri.Z() );
243 aSrcY->SetPoint2( aEndY.X(), aEndY.Y(), aEndY.Z() );
245 aSrcZ->SetPoint1( anOri.X(), anOri.Y(), anOri.Z() );
246 aSrcZ->SetPoint2( aEndZ.X(), aEndZ.Y(), aEndZ.Z() );
248 vtkAppendPolyData* aRes = vtkAppendPolyData::New();
249 aRes->AddInput( aSrcX->GetOutput() );
250 aRes->AddInput( aSrcY->GetOutput() );
251 aRes->AddInput( aSrcZ->GetOutput() );
253 myMapper->SetInput( aRes->GetOutput() );
254 SALOME_Actor::SetMapper( myMapper );
262 void GEOM_VTKTrihedron::SetVisibility( VTKViewer_Trihedron::TVisibility theVis )
264 for ( int i = 0; i < 3; i++ )
265 myAxis[i]->SetVisibility( theVis );
268 void GEOM_VTKTrihedron::AddToRender( vtkRenderer* theRenderer )
270 vtkCamera* aCamera = theRenderer->GetActiveCamera();
271 for(int i = 0; i < 3; i++)
273 myAxis[i]->AddToRender(theRenderer);
274 myAxis[i]->SetCamera(aCamera);
277 theRenderer->AddActor( this );
280 void GEOM_VTKTrihedron::RemoveFromRender( vtkRenderer* theRenderer )
282 for(int i = 0; i < 3; i++)
284 myAxis[i]->RemoveFromRender(theRenderer);
287 theRenderer->RemoveActor( this );
290 int GEOM_VTKTrihedron::GetVisibleActorCount(vtkRenderer* theRenderer)
292 vtkActorCollection* aCollection = theRenderer->GetActors();
293 aCollection->InitTraversal();
295 while( vtkActor* prop = aCollection->GetNextActor() )
296 if ( prop->GetVisibility() )
297 if ( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( prop ) )
298 if ( !anActor->IsInfinitive() )
301 vtkCamera* aCamera = theRenderer->GetActiveCamera();
302 for(int i = 0; i < 3; i++)
303 myAxis[i]->SetCamera( aCamera );
308 void GEOM_VTKTrihedron::SetCamera( vtkCamera* theCamera )
310 for(int i = 0; i < 3; i++)
311 myAxis[i]->SetCamera( theCamera );
314 void GEOM_VTKTrihedron::SetPlacement( const Handle(Geom_Axis2Placement)& thePlc )
316 gp_Ax2 anAx2 = thePlc->Ax2();
318 myDirX = anAx2.XDirection();
319 myDirY = anAx2.YDirection();
320 myDirZ = anAx2.Direction();
322 myLocation = anAx2.Axis().Location();
324 if ( myAxis[ 0 ] != 0 ) myAxis[ 0 ]->Delete();
325 if ( myAxis[ 1 ] != 0 ) myAxis[ 1 ]->Delete();
326 if ( myAxis[ 2 ] != 0 ) myAxis[ 2 ]->Delete();
328 myAxis[ 0 ] = GEOM_VTKTrihedronAxis::New();
329 myAxis[ 1 ] = GEOM_VTKTrihedronAxis::New();
330 myAxis[ 2 ] = GEOM_VTKTrihedronAxis::New();
332 ( (GEOM_VTKTrihedronAxis*)myAxis[ 0 ] )->SetAxis( gp_Ax1( myLocation, myDirX ), 0, myColor );
333 ( (GEOM_VTKTrihedronAxis*)myAxis[ 1 ] )->SetAxis( gp_Ax1( myLocation, myDirY ), 1, myColor );
334 ( (GEOM_VTKTrihedronAxis*)myAxis[ 2 ] )->SetAxis( gp_Ax1( myLocation, myDirZ ), 2, myColor );
339 vtkMapper* GEOM_VTKTrihedron::GetMapper()
344 void GEOM_VTKTrihedron::Render(vtkRenderer* r, vtkMapper *)
346 ( (GEOM_VTKTrihedronAxis*)myAxis[ 0 ] )->Render( r );
347 ( (GEOM_VTKTrihedronAxis*)myAxis[ 1 ] )->Render( r );
348 ( (GEOM_VTKTrihedronAxis*)myAxis[ 2 ] )->Render( r );
351 void GEOM_VTKTrihedron::SetColor( vtkFloatingPointType r, vtkFloatingPointType g, vtkFloatingPointType b )
357 if ( myAxis[ 0 ] ) ( (GEOM_VTKTrihedronAxis*)myAxis[ 0 ] )->SetColor( myColor );
358 if ( myAxis[ 1 ] ) ( (GEOM_VTKTrihedronAxis*)myAxis[ 1 ] )->SetColor( myColor );
359 if ( myAxis[ 2 ] ) ( (GEOM_VTKTrihedronAxis*)myAxis[ 2 ] )->SetColor( myColor );
362 void GEOM_VTKTrihedron::GetColor( vtkFloatingPointType& r, vtkFloatingPointType& g, vtkFloatingPointType& b )
369 bool GEOM_VTKTrihedron::IsSetCamera() const
374 bool GEOM_VTKTrihedron::IsResizable() const