1 // SMESH OBJECT : interactive object for SMESH 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
30 #include "VISU_GaussPtsDeviceActor.h"
32 #include "VISU_GaussPointsPL.hxx"
33 #include "VISU_OpenGLPointSpriteMapper.hxx"
35 #include "VTKViewer_Transform.h"
36 #include "VTKViewer_TransformFilter.h"
37 #include "VTKViewer_PassThroughFilter.h"
39 #include <vtkObjectFactory.h>
40 #include <vtkPolyData.h>
41 #include <vtkRenderer.h>
42 #include <vtkTextProperty.h>
43 #include <vtkProperty.h>
44 #include <vtkTexture.h>
46 #include "utilities.h"
49 static int MYDEBUG = 0;
51 static int MYDEBUG = 0;
57 //----------------------------------------------------------------
58 vtkStandardNewMacro(VISU_GaussPtsDeviceActor);
61 VISU_GaussPtsDeviceActor
62 ::VISU_GaussPtsDeviceActor():
63 myGeomFilter(VTKViewer_GeometryFilter::New()),
64 myTransformFilter(VTKViewer_TransformFilter::New())
66 if(MYDEBUG) MESSAGE("VISU_GaussPtsDeviceActor - "<<this);
68 myGeomFilter->Delete();
69 myTransformFilter->Delete();
71 for(int i = 0; i < 3; i++){
72 PPassThroughFilter aFilter(VTKViewer_PassThroughFilter::New());
73 myPassFilter.push_back(aFilter);
79 VISU_GaussPtsDeviceActor
80 ::~VISU_GaussPtsDeviceActor()
82 if(MYDEBUG) MESSAGE("~VISU_GaussPtsDeviceActor - "<<this);
86 //----------------------------------------------------------------
88 VISU_GaussPtsDeviceActor
89 ::Render(vtkRenderer *ren, vtkMapper *vtkNotUsed(m))
91 if (this->Mapper == NULL)
93 vtkErrorMacro("No mapper for actor.");
97 // render the property
100 // force creation of a property
103 this->Property->Render(this, ren);
104 if (this->BackfaceProperty)
106 this->BackfaceProperty->BackfaceRender(this, ren);
107 this->Device->SetBackfaceProperty(this->BackfaceProperty);
109 this->Device->SetProperty(this->Property);
111 // render the texture
114 this->Texture->Render(ren);
117 // make sure the device has the same matrix
118 vtkMatrix4x4 *matrix = this->Device->GetUserMatrix();
119 this->GetMatrix(matrix);
121 this->Device->Render(ren,Mapper);
122 this->EstimatedRenderTime = Mapper->GetTimeToDraw();
126 //----------------------------------------------------------------
128 VISU_GaussPtsDeviceActor
129 ::AddToRender(vtkRenderer* theRenderer)
131 theRenderer->AddActor(this);
135 VISU_GaussPtsDeviceActor
136 ::RemoveFromRender(vtkRenderer* theRenderer)
138 theRenderer->RemoveActor(this);
142 VISU_GaussPtsDeviceActor
143 ::SetTransform(VTKViewer_Transform* theTransform)
145 myTransformFilter->SetTransform(theTransform);
148 VISU_OpenGLPointSpriteMapper*
149 VISU_GaussPtsDeviceActor
152 return myMapper.GetPointer();
156 //----------------------------------------------------------------------------
158 VISU_GaussPtsDeviceActor
159 ::SetPipeLine(VISU_GaussPointsPL* thePipeLine)
161 myPipeLine = thePipeLine;
162 myMapper = thePipeLine->GetPSMapper();
163 vtkPolyData* aDataSet = myMapper->GetInput();
166 myPassFilter[ anId ]->SetInput( aDataSet );
167 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
170 myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
173 myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() );
175 myMapper->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
177 Superclass::SetMapper( myMapper.GetPointer() );
181 VISU_GaussPtsDeviceActor
184 return myPipeLine.GetPointer();
188 VISU_GaussPtsDeviceActor
189 ::ShallowCopyPL(VISU_GaussPointsPL* thePipeLine)
191 myPipeLine->ShallowCopy(thePipeLine);
195 //============================================================================
196 #include <vtkActor.h>
197 #include <vtkProperty.h>
198 #include <vtkConeSource.h>
199 #include <vtkAppendPolyData.h>
200 #include <vtkPolyDataMapper.h>
203 //----------------------------------------------------------------------------
204 vtkStandardNewMacro(VISU_CursorPyramid);
206 //----------------------------------------------------------------------------
208 ::VISU_CursorPyramid():
211 myMagnification(1.0),
214 myAppendFilter(vtkAppendPolyData::New()),
215 myMapper(vtkPolyDataMapper::New())
217 myAppendFilter->Delete();
220 myMapper->SetInput(myAppendFilter->GetOutput());
222 for(int i = 0; i < myNbCones; i++){
223 vtkConeSource* aConeSource = vtkConeSource::New();
224 myAppendFilter->AddInput(aConeSource->GetOutput());
225 aConeSource->SetResolution(4);
226 mySources[i] = aConeSource;
227 aConeSource->Delete();
232 //----------------------------------------------------------------------------
235 ::Render(vtkRenderer *ren, vtkMapper *vtkNotUsed(m))
239 vtkErrorMacro("No mapper for actor.");
244 float aMRadius = myRadius*myMagnification;
245 Init(myHeight,aMRadius*myCursorSize);
248 float aPoint1[3] = {0.0, 0.0, 0.0};
249 ren->SetDisplayPoint(aPoint1);
250 ren->DisplayToWorld();
251 ren->GetWorldPoint(aPoint1);
253 float aPoint2[3] = {0.0, myClamp, 0.0};
254 ren->SetDisplayPoint(aPoint2);
255 ren->DisplayToWorld();
256 ren->GetWorldPoint(aPoint2);
259 (aPoint2[0] - aPoint1[0])*(aPoint2[0] - aPoint1[0]) +
260 (aPoint2[1] - aPoint1[1])*(aPoint2[1] - aPoint1[1]) +
261 (aPoint2[2] - aPoint1[2])*(aPoint2[2] - aPoint1[2]);
263 aWorldClamp = sqrt(aWorldClamp);
264 float aMDiameter = 2.0 * aMRadius;
265 float aCoeff = aWorldClamp / aMDiameter;
268 this->SetScale(aCoeff);
269 //Init(myHeight/aCoeff,aMRadius*aCoeff);
273 if (this->Mapper == NULL)
275 vtkErrorMacro("No mapper for actor.");
279 // render the property
282 // force creation of a property
285 this->Property->Render(this, ren);
286 if (this->BackfaceProperty)
288 this->BackfaceProperty->BackfaceRender(this, ren);
289 this->Device->SetBackfaceProperty(this->BackfaceProperty);
291 this->Device->SetProperty(this->Property);
293 // render the texture
296 this->Texture->Render(ren);
299 // make sure the device has the same matrix
300 vtkMatrix4x4 *matrix = this->Device->GetUserMatrix();
301 this->GetMatrix(matrix);
303 this->Device->Render(ren,Mapper);
304 this->EstimatedRenderTime = Mapper->GetTimeToDraw();
308 //----------------------------------------------------------------------------
311 ::AddToRender(vtkRenderer* theRenderer)
313 theRenderer->AddActor(this);
318 ::RemoveFromRender(vtkRenderer* theRenderer)
320 theRenderer->RemoveActor(this);
323 //----------------------------------------------------------------------------
326 ::SetPreferences(float theHeight,
329 Init(theHeight, theCursorSize, myRadius, myMagnification, myClamp, GetPosition(), GetProperty()->GetColor());
332 //----------------------------------------------------------------------------
335 ::Init(float theHeight,
338 float theMagnification,
343 Init(theHeight,theRadius*theMagnification*theCursorSize);
344 SetPosition(thePos[0],thePos[1],thePos[2]);
345 GetProperty()->SetColor(theColor);
346 SetMapper(myMapper.GetPointer());
348 myHeight = theHeight;
349 myCursorSize = theCursorSize;
351 myRadius = theRadius;
352 myMagnification = theMagnification;
360 ::Init(float theHeight,
363 for(int i = 0; i < myNbCones; ++i){
364 vtkConeSource* aSource = mySources[i].GetPointer();
365 aSource->SetHeight(theHeight);
366 // Set the angle of the cone. As a side effect, the angle plus height sets
367 // the base radius of the cone.
368 aSource->SetAngle(20.0);
371 float aDisplacement = -0.5*theHeight - theRadius;
374 mySources[0]->SetDirection(1.0, 0.0, 0.0);
375 mySources[0]->SetCenter(aDisplacement, 0.0, 0.0);
377 // It is impossible to inverse direction around X axis (VTK bug)
378 mySources[1]->SetDirection(-VTK_LARGE_FLOAT, 1.0, 0.0); // A workaround
379 mySources[1]->SetCenter(-aDisplacement, 0.0, 0.0);
382 mySources[2]->SetDirection(0.0, 1.0, 0.0);
383 mySources[2]->SetCenter(0.0, aDisplacement, 0.0);
385 mySources[3]->SetDirection(0.0, -1.0, 0.0);
386 mySources[3]->SetCenter(0.0, -aDisplacement, 0.0);
389 mySources[4]->SetDirection(0.0, 0.0, 1.0);
390 mySources[4]->SetCenter(0.0, 0.0, aDisplacement);
392 mySources[5]->SetDirection(0.0, 0.0, -1.0);
393 mySources[5]->SetCenter(0.0, 0.0, -aDisplacement);
397 //----------------------------------------------------------------------------
398 #include <vtkViewport.h>
399 #include <vtkWindow.h>
401 #include <vtkPolyData.h>
402 #include <vtkPolyDataMapper2D.h>
403 #include <vtkActor2D.h>
404 #include <vtkTimeStamp.h>
405 #include <vtkTextProperty.h>
406 #include <vtkTextActor.h>
407 #include <vtkTextMapper.h>
408 #include <vtkPoints.h>
409 #include <vtkCellArray.h>
410 #include <vtkProperty2D.h>
411 //==================================================================
412 vtkCxxRevisionMacro(VISU_FramedTextActor, "$Revision$");
413 vtkStandardNewMacro(VISU_FramedTextActor);
415 //==================================================================
416 // function : VISU_FramedTextActor
418 //==================================================================
419 VISU_FramedTextActor::VISU_FramedTextActor()
421 PositionCoordinate->SetCoordinateSystemToNormalizedViewport();
424 myBar = vtkPolyData::New();
425 myBarMapper = vtkPolyDataMapper2D::New();
426 myBarMapper->SetInput(myBar);
427 myBarActor = vtkActor2D::New();
428 myBarActor->SetMapper(myBarMapper);
429 myBarActor->GetProperty()->SetOpacity(1.-myTransparency);
430 myBarActor->GetProperty()->SetColor(.5, .5, .5);
432 myTextProperty = vtkTextProperty::New();
433 myTextProperty->SetFontSize(12);
434 myTextProperty->SetBold(0);
435 myTextProperty->SetItalic(0);
436 myTextProperty->SetShadow(1);
437 myTextProperty->SetFontFamilyToArial();
439 myTextMapper=vtkTextMapper::New();
440 myTextMapper->SetInput("some text");
441 myTextMapper->GetTextProperty()->ShallowCopy(myTextProperty);
442 myTextActor=vtkActor2D::New();
443 myTextActor->SetMapper(myTextMapper);
445 myBarActor->SetVisibility(1);
446 myTextActor->SetVisibility(1);
447 myBarActor->SetPickable(0);
448 myTextActor->SetPickable(0);
449 //----------------------------------------------------------
450 myModePosition=0;// 0 -centered below the point
451 // 1 -top left corner of the 3D view window
453 for(int i=0; i<4; i++) {
454 myWorldPoint[i] = 0.;
459 //==================================================================
462 //==================================================================
463 VISU_FramedTextActor::~VISU_FramedTextActor()
465 myTextActor->Delete();
466 myTextMapper->Delete();
467 myTextProperty->Delete();
468 myBarActor->Delete();
469 myBarMapper->Delete();
472 //==================================================================
473 // function : SetVisibility
475 //==================================================================
476 void VISU_FramedTextActor::SetVisibility (int theVisibility)
478 myBarActor->SetVisibility(theVisibility);
479 myTextActor->SetVisibility(theVisibility);
481 //==================================================================
482 // function : GetVisibility
484 //==================================================================
485 int VISU_FramedTextActor::GetVisibility()
487 return myBarActor->GetVisibility();
489 //==================================================================
490 // function : SetPickable
492 //==================================================================
493 void VISU_FramedTextActor::SetPickable (int thePickability)
495 myBarActor->SetPickable(thePickability);
496 myTextActor->SetPickable(thePickability);
498 //==================================================================
499 // function : GetPickable
501 //==================================================================
502 int VISU_FramedTextActor::GetPickable()
504 return myBarActor->GetPickable();
506 //==================================================================
507 // function : SetTransparency
509 //==================================================================
510 void VISU_FramedTextActor::SetTransparency(const float theTransparency)
512 if (theTransparency>=0. && theTransparency<=1.){
513 myTransparency=theTransparency;
514 myBarActor->GetProperty()->SetOpacity(1.-myTransparency);
518 //==================================================================
519 // function : GetTransparency
521 //==================================================================
522 float VISU_FramedTextActor::GetTransparency()const
524 return myTransparency;
526 //==================================================================
527 // function : SetText
529 //==================================================================
530 void VISU_FramedTextActor::SetText(const char* theText)
532 myTextMapper->SetInput(theText);
535 //==================================================================
536 // function : GetText
538 //==================================================================
539 char* VISU_FramedTextActor::GetText()
541 return myTextMapper->GetInput();
543 //==================================================================
544 // function : SetModePosition
546 //==================================================================
547 void VISU_FramedTextActor::SetModePosition(const int theMode)
549 myModePosition=theMode;
552 //==================================================================
553 // function : GetModePosition
555 //==================================================================
556 int VISU_FramedTextActor::GetModePosition()const
558 return myModePosition;
560 //==================================================================
561 // function : SetWorldPoint
563 //==================================================================
564 void VISU_FramedTextActor::SetWorldPoint(const float theWorldPoint[4])
566 for(int i = 0; i<4; ++i) {
567 myWorldPoint[i] = theWorldPoint[i];
571 //==================================================================
572 // function : GetWorldPoint
574 //==================================================================
575 const float* VISU_FramedTextActor::GetWorldPoint()const
579 //==================================================================
580 // function : SetDistance
582 //==================================================================
583 void VISU_FramedTextActor::SetDistance(const float theDistance)
585 myDistance=theDistance;
587 //==================================================================
588 // function : GetDistance
590 //==================================================================
591 float VISU_FramedTextActor::GetDistance()const
595 //==================================================================
596 // function : ReleaseGraphicsResources
598 //==================================================================
599 void VISU_FramedTextActor::ReleaseGraphicsResources(vtkWindow *win)
601 myTextActor->ReleaseGraphicsResources(win);
602 myBarActor->ReleaseGraphicsResources(win);
604 //==================================================================
605 // function : RenderOverlay
607 //==================================================================
608 int VISU_FramedTextActor::RenderOverlay(vtkViewport *viewport)
610 int renderedSomething = 0;
611 myBarActor->RenderOverlay(viewport);
612 renderedSomething +=myTextActor->RenderOverlay(viewport);
613 return renderedSomething;
615 //==================================================================
616 // function : RenderOpaqueGeometry
618 //==================================================================
621 ::RenderOpaqueGeometry(vtkViewport *theViewport)
623 int anIsRenderedSomething = 0;
624 int* aViewportSize = theViewport->GetSize();
625 if(aViewportSize[0] == 1 || aViewportSize[1] == 1)
626 return anIsRenderedSomething;
631 vtkPoints *aPoints = vtkPoints::New();
632 aPoints->SetNumberOfPoints(aNbPoints);
633 myBar->SetPoints(aPoints);
636 vtkCellArray *aPolys = vtkCellArray::New();
637 aPolys->Allocate(aPolys->EstimateSize(1,4));
638 vtkIdType aPointsIds[4] = {0, 1, 3, 2};
639 aPolys->InsertNextCell(4,aPointsIds);
640 myBar->SetPolys(aPolys);
644 myTextMapper->GetSize(theViewport, aTextSize);
645 int aBarWidth = aTextSize[0];
646 int aBarHeight = aTextSize[1];
648 if (myModePosition==0) {
649 theViewport->SetWorldPoint(myWorldPoint);
650 theViewport->WorldToDisplay();
652 float aSelectionPoint[3];
653 theViewport->GetDisplayPoint(aSelectionPoint);
654 float u = aSelectionPoint[0];
655 float v = aSelectionPoint[1] - myDistance;
656 theViewport->ViewportToNormalizedViewport(u, v);
657 PositionCoordinate->SetValue(u, v);
659 myTextProperty->SetJustificationToCentered();
660 myTextProperty->SetVerticalJustificationToTop();
663 aPoints->SetPoint(0, -aBarWidth, 0.0, 0.0);
664 aPoints->SetPoint(1, -aBarWidth, -aBarHeight, 0.0);
665 aPoints->SetPoint(2, aBarWidth, 0.0, 0.0);
666 aPoints->SetPoint(3, aBarWidth, -aBarHeight, 0.0);
668 else {//if (myModePosition==1) {
669 PositionCoordinate->SetValue(0.0, 1.0);
670 myTextProperty->SetJustificationToLeft();
671 myTextProperty->SetVerticalJustificationToTop();
673 aPoints->SetPoint(0, 0.0, 0.0, 0.0);
674 aPoints->SetPoint(1, 0.0, -aBarHeight, 0.0);
675 aPoints->SetPoint(2, aBarWidth, 0.0, 0.0);
676 aPoints->SetPoint(3, aBarWidth, -aBarHeight, 0.0);
679 myTextMapper->GetTextProperty()->ShallowCopy(myTextProperty);
680 myBarActor ->GetPositionCoordinate()->SetReferenceCoordinate(PositionCoordinate);
681 myTextActor->GetPositionCoordinate()->SetReferenceCoordinate(PositionCoordinate);
683 myBuildTime.Modified();
685 return anIsRenderedSomething;