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 VISU_GaussPtsDeviceActor
159 if(Superclass::GetPickable()){
160 if(vtkMapper* aMapper = GetMapper()){
161 if(vtkDataSet* aDataSet= aMapper->GetInput()){
163 return aDataSet->GetNumberOfCells() > 0;
172 //----------------------------------------------------------------------------
174 VISU_GaussPtsDeviceActor
175 ::SetPipeLine(VISU_GaussPointsPL* thePipeLine)
177 myPipeLine = thePipeLine;
178 myMapper = thePipeLine->GetPSMapper();
179 vtkPolyData* aDataSet = myMapper->GetInput();
182 myPassFilter[ anId ]->SetInput( aDataSet );
183 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
186 myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
189 myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() );
191 myMapper->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
193 Superclass::SetMapper( myMapper.GetPointer() );
197 VISU_GaussPtsDeviceActor
200 return myPipeLine.GetPointer();
204 VISU_GaussPtsDeviceActor
205 ::ShallowCopyPL(VISU_GaussPointsPL* thePipeLine)
207 myPipeLine->ShallowCopy(thePipeLine);
211 //============================================================================
212 #include <vtkActor.h>
213 #include <vtkProperty.h>
214 #include <vtkConeSource.h>
215 #include <vtkAppendPolyData.h>
216 #include <vtkPolyDataMapper.h>
219 //----------------------------------------------------------------------------
220 vtkStandardNewMacro(VISU_CursorPyramid);
222 //----------------------------------------------------------------------------
224 ::VISU_CursorPyramid():
227 myMagnification(1.0),
230 myAppendFilter(vtkAppendPolyData::New()),
231 myMapper(vtkPolyDataMapper::New())
233 myAppendFilter->Delete();
236 myMapper->SetInput(myAppendFilter->GetOutput());
238 for(int i = 0; i < myNbCones; i++){
239 vtkConeSource* aConeSource = vtkConeSource::New();
240 myAppendFilter->AddInput(aConeSource->GetOutput());
241 aConeSource->SetResolution(4);
242 mySources[i] = aConeSource;
243 aConeSource->Delete();
248 //----------------------------------------------------------------------------
251 ::Render(vtkRenderer *ren, vtkMapper *vtkNotUsed(m))
255 vtkErrorMacro("No mapper for actor.");
260 vtkFloatingPointType aMRadius = myRadius*myMagnification;
261 Init(myHeight,aMRadius*myCursorSize);
264 vtkFloatingPointType aPoint1[3] = {0.0, 0.0, 0.0};
265 ren->SetDisplayPoint(aPoint1);
266 ren->DisplayToWorld();
267 ren->GetWorldPoint(aPoint1);
269 vtkFloatingPointType aPoint2[3] = {0.0, myClamp, 0.0};
270 ren->SetDisplayPoint(aPoint2);
271 ren->DisplayToWorld();
272 ren->GetWorldPoint(aPoint2);
274 vtkFloatingPointType aWorldClamp =
275 (aPoint2[0] - aPoint1[0])*(aPoint2[0] - aPoint1[0]) +
276 (aPoint2[1] - aPoint1[1])*(aPoint2[1] - aPoint1[1]) +
277 (aPoint2[2] - aPoint1[2])*(aPoint2[2] - aPoint1[2]);
279 aWorldClamp = sqrt(aWorldClamp);
280 vtkFloatingPointType aMDiameter = 2.0 * aMRadius;
281 vtkFloatingPointType aCoeff = aWorldClamp / aMDiameter;
284 this->SetScale(aCoeff);
285 //Init(myHeight/aCoeff,aMRadius*aCoeff);
289 if (this->Mapper == NULL)
291 vtkErrorMacro("No mapper for actor.");
295 // render the property
298 // force creation of a property
301 this->Property->Render(this, ren);
302 if (this->BackfaceProperty)
304 this->BackfaceProperty->BackfaceRender(this, ren);
305 this->Device->SetBackfaceProperty(this->BackfaceProperty);
307 this->Device->SetProperty(this->Property);
309 // render the texture
312 this->Texture->Render(ren);
315 // make sure the device has the same matrix
316 vtkMatrix4x4 *matrix = this->Device->GetUserMatrix();
317 this->GetMatrix(matrix);
319 this->Device->Render(ren,Mapper);
320 this->EstimatedRenderTime = Mapper->GetTimeToDraw();
324 //----------------------------------------------------------------------------
327 ::AddToRender(vtkRenderer* theRenderer)
329 theRenderer->AddActor(this);
334 ::RemoveFromRender(vtkRenderer* theRenderer)
336 theRenderer->RemoveActor(this);
339 //----------------------------------------------------------------------------
342 ::SetPreferences(vtkFloatingPointType theHeight,
343 vtkFloatingPointType theCursorSize)
345 Init(theHeight, theCursorSize, myRadius, myMagnification, myClamp, GetPosition(), GetProperty()->GetColor());
348 //----------------------------------------------------------------------------
351 ::Init(vtkFloatingPointType theHeight,
352 vtkFloatingPointType theCursorSize,
353 vtkFloatingPointType theRadius,
354 vtkFloatingPointType theMagnification,
355 vtkFloatingPointType theClamp,
356 vtkFloatingPointType thePos[3],
357 vtkFloatingPointType theColor[3])
359 Init(theHeight,theRadius*theMagnification*theCursorSize);
360 SetPosition(thePos[0],thePos[1],thePos[2]);
361 GetProperty()->SetColor(theColor);
362 SetMapper(myMapper.GetPointer());
364 myHeight = theHeight;
365 myCursorSize = theCursorSize;
367 myRadius = theRadius;
368 myMagnification = theMagnification;
376 ::Init(vtkFloatingPointType theHeight,
377 vtkFloatingPointType theRadius)
379 for(int i = 0; i < myNbCones; ++i){
380 vtkConeSource* aSource = mySources[i].GetPointer();
381 aSource->SetHeight(theHeight);
382 // Set the angle of the cone. As a side effect, the angle plus height sets
383 // the base radius of the cone.
384 aSource->SetAngle(20.0);
387 vtkFloatingPointType aDisplacement = -0.5*theHeight - theRadius;
390 mySources[0]->SetDirection(1.0, 0.0, 0.0);
391 mySources[0]->SetCenter(aDisplacement, 0.0, 0.0);
393 // It is impossible to inverse direction around X axis (VTK bug)
394 mySources[1]->SetDirection(-VTK_LARGE_FLOAT, 1.0, 0.0); // A workaround
395 mySources[1]->SetCenter(-aDisplacement, 0.0, 0.0);
398 mySources[2]->SetDirection(0.0, 1.0, 0.0);
399 mySources[2]->SetCenter(0.0, aDisplacement, 0.0);
401 mySources[3]->SetDirection(0.0, -1.0, 0.0);
402 mySources[3]->SetCenter(0.0, -aDisplacement, 0.0);
405 mySources[4]->SetDirection(0.0, 0.0, 1.0);
406 mySources[4]->SetCenter(0.0, 0.0, aDisplacement);
408 mySources[5]->SetDirection(0.0, 0.0, -1.0);
409 mySources[5]->SetCenter(0.0, 0.0, -aDisplacement);
413 //----------------------------------------------------------------------------
414 #include <vtkViewport.h>
415 #include <vtkWindow.h>
417 #include <vtkPolyData.h>
418 #include <vtkPolyDataMapper2D.h>
419 #include <vtkActor2D.h>
420 #include <vtkTimeStamp.h>
421 #include <vtkTextProperty.h>
422 #include <vtkTextActor.h>
423 #include <vtkTextMapper.h>
424 #include <vtkPoints.h>
425 #include <vtkCellArray.h>
426 #include <vtkProperty2D.h>
427 //==================================================================
428 vtkCxxRevisionMacro(VISU_FramedTextActor, "$Revision$");
429 vtkStandardNewMacro(VISU_FramedTextActor);
431 //==================================================================
432 // function : VISU_FramedTextActor
434 //==================================================================
435 VISU_FramedTextActor::VISU_FramedTextActor()
437 PositionCoordinate->SetCoordinateSystemToNormalizedViewport();
440 myBar = vtkPolyData::New();
441 myBarMapper = vtkPolyDataMapper2D::New();
442 myBarMapper->SetInput(myBar);
443 myBarActor = vtkActor2D::New();
444 myBarActor->SetMapper(myBarMapper);
445 myBarActor->GetProperty()->SetOpacity(1.-myTransparency);
446 myBarActor->GetProperty()->SetColor(.5, .5, .5);
448 myTextProperty = vtkTextProperty::New();
449 myTextProperty->SetFontSize(12);
450 myTextProperty->SetBold(0);
451 myTextProperty->SetItalic(0);
452 myTextProperty->SetShadow(1);
453 myTextProperty->SetFontFamilyToArial();
455 myTextMapper=vtkTextMapper::New();
456 myTextMapper->SetInput("some text");
457 myTextMapper->GetTextProperty()->ShallowCopy(myTextProperty);
458 myTextActor=vtkActor2D::New();
459 myTextActor->SetMapper(myTextMapper);
461 myBarActor->SetVisibility(1);
462 myTextActor->SetVisibility(1);
463 myBarActor->SetPickable(0);
464 myTextActor->SetPickable(0);
465 //----------------------------------------------------------
466 myModePosition=0;// 0 -centered below the point
467 // 1 -top left corner of the 3D view window
469 for(int i=0; i<4; i++) {
470 myWorldPoint[i] = 0.;
475 //==================================================================
478 //==================================================================
479 VISU_FramedTextActor::~VISU_FramedTextActor()
481 myTextActor->Delete();
482 myTextMapper->Delete();
483 myTextProperty->Delete();
484 myBarActor->Delete();
485 myBarMapper->Delete();
488 //==================================================================
489 // function : SetVisibility
491 //==================================================================
492 void VISU_FramedTextActor::SetVisibility (int theVisibility)
494 myBarActor->SetVisibility(theVisibility);
495 myTextActor->SetVisibility(theVisibility);
497 //==================================================================
498 // function : GetVisibility
500 //==================================================================
501 int VISU_FramedTextActor::GetVisibility()
503 return myBarActor->GetVisibility();
505 //==================================================================
506 // function : SetPickable
508 //==================================================================
509 void VISU_FramedTextActor::SetPickable (int thePickability)
511 myBarActor->SetPickable(thePickability);
512 myTextActor->SetPickable(thePickability);
514 //==================================================================
515 // function : GetPickable
517 //==================================================================
518 int VISU_FramedTextActor::GetPickable()
520 return myBarActor->GetPickable();
522 //==================================================================
523 // function : SetTransparency
525 //==================================================================
526 void VISU_FramedTextActor::SetTransparency(const vtkFloatingPointType theTransparency)
528 if (theTransparency>=0. && theTransparency<=1.){
529 myTransparency=theTransparency;
530 myBarActor->GetProperty()->SetOpacity(1.-myTransparency);
534 //==================================================================
535 // function : GetTransparency
537 //==================================================================
538 vtkFloatingPointType VISU_FramedTextActor::GetTransparency()const
540 return myTransparency;
542 //==================================================================
543 // function : SetText
545 //==================================================================
546 void VISU_FramedTextActor::SetText(const char* theText)
548 myTextMapper->SetInput(theText);
551 //==================================================================
552 // function : GetText
554 //==================================================================
555 char* VISU_FramedTextActor::GetText()
557 return myTextMapper->GetInput();
559 //==================================================================
560 // function : SetModePosition
562 //==================================================================
563 void VISU_FramedTextActor::SetModePosition(const int theMode)
565 myModePosition=theMode;
568 //==================================================================
569 // function : GetModePosition
571 //==================================================================
572 int VISU_FramedTextActor::GetModePosition()const
574 return myModePosition;
576 //==================================================================
577 // function : SetWorldPoint
579 //==================================================================
580 void VISU_FramedTextActor::SetWorldPoint(const vtkFloatingPointType theWorldPoint[4])
582 for(int i = 0; i<4; ++i) {
583 myWorldPoint[i] = theWorldPoint[i];
587 //==================================================================
588 // function : GetWorldPoint
590 //==================================================================
591 const vtkFloatingPointType* VISU_FramedTextActor::GetWorldPoint()const
595 //==================================================================
596 // function : SetDistance
598 //==================================================================
599 void VISU_FramedTextActor::SetDistance(const vtkFloatingPointType theDistance)
601 myDistance=theDistance;
603 //==================================================================
604 // function : GetDistance
606 //==================================================================
607 vtkFloatingPointType VISU_FramedTextActor::GetDistance()const
611 //==================================================================
612 // function : ReleaseGraphicsResources
614 //==================================================================
615 void VISU_FramedTextActor::ReleaseGraphicsResources(vtkWindow *win)
617 myTextActor->ReleaseGraphicsResources(win);
618 myBarActor->ReleaseGraphicsResources(win);
620 //==================================================================
621 // function : RenderOverlay
623 //==================================================================
624 int VISU_FramedTextActor::RenderOverlay(vtkViewport *viewport)
626 int renderedSomething = 0;
627 myBarActor->RenderOverlay(viewport);
628 renderedSomething +=myTextActor->RenderOverlay(viewport);
629 return renderedSomething;
631 //==================================================================
632 // function : RenderOpaqueGeometry
634 //==================================================================
637 ::RenderOpaqueGeometry(vtkViewport *theViewport)
639 int anIsRenderedSomething = 0;
640 int* aViewportSize = theViewport->GetSize();
641 if(aViewportSize[0] == 1 || aViewportSize[1] == 1)
642 return anIsRenderedSomething;
647 vtkPoints *aPoints = vtkPoints::New();
648 aPoints->SetNumberOfPoints(aNbPoints);
649 myBar->SetPoints(aPoints);
652 vtkCellArray *aPolys = vtkCellArray::New();
653 aPolys->Allocate(aPolys->EstimateSize(1,4));
654 vtkIdType aPointsIds[4] = {0, 1, 3, 2};
655 aPolys->InsertNextCell(4,aPointsIds);
656 myBar->SetPolys(aPolys);
660 myTextMapper->GetSize(theViewport, aTextSize);
661 int aBarWidth = aTextSize[0];
662 int aBarHeight = aTextSize[1];
664 if (myModePosition==0) {
665 theViewport->SetWorldPoint(myWorldPoint);
666 theViewport->WorldToDisplay();
668 vtkFloatingPointType aSelectionPoint[3];
669 theViewport->GetDisplayPoint(aSelectionPoint);
670 vtkFloatingPointType u = aSelectionPoint[0];
671 vtkFloatingPointType v = aSelectionPoint[1] - myDistance;
672 theViewport->ViewportToNormalizedViewport(u, v);
673 PositionCoordinate->SetValue(u, v);
675 myTextProperty->SetJustificationToCentered();
676 myTextProperty->SetVerticalJustificationToTop();
679 aPoints->SetPoint(0, -aBarWidth, 0.0, 0.0);
680 aPoints->SetPoint(1, -aBarWidth, -aBarHeight, 0.0);
681 aPoints->SetPoint(2, aBarWidth, 0.0, 0.0);
682 aPoints->SetPoint(3, aBarWidth, -aBarHeight, 0.0);
684 else {//if (myModePosition==1) {
685 PositionCoordinate->SetValue(0.0, 1.0);
686 myTextProperty->SetJustificationToLeft();
687 myTextProperty->SetVerticalJustificationToTop();
689 aPoints->SetPoint(0, 0.0, 0.0, 0.0);
690 aPoints->SetPoint(1, 0.0, -aBarHeight, 0.0);
691 aPoints->SetPoint(2, aBarWidth, 0.0, 0.0);
692 aPoints->SetPoint(3, aBarWidth, -aBarHeight, 0.0);
695 myTextMapper->GetTextProperty()->ShallowCopy(myTextProperty);
696 myBarActor ->GetPositionCoordinate()->SetReferenceCoordinate(PositionCoordinate);
697 myTextActor->GetPositionCoordinate()->SetReferenceCoordinate(PositionCoordinate);
699 myBuildTime.Modified();
701 return anIsRenderedSomething;