1 // VISU OBJECT : interactive object for VISU entities implementation
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
23 // File: VISU_PipeLine.cxx
24 // Author: Alexey PETROV
28 #include "VISU_VectorsPL.hxx"
29 #include "VISU_PipeLineUtils.hxx"
30 #include "SALOME_TransformFilter.h"
31 #include "SALOME_Transform.h"
33 #include <vtkGlyph3D.h>
34 #include <vtkConeSource.h>
35 #include <vtkLineSource.h>
36 #include <vtkGlyphSource2D.h>
38 vtkStandardNewMacro(VISU_VectorsPL);
40 VISU_VectorsPL::VISU_VectorsPL(){
41 myGlyph = vtkGlyph3D::New();
43 myGlyphSource = vtkGlyphSource2D::New();
44 myConeSource = vtkConeSource::New();
45 myLineSource = vtkLineSource::New();
47 myCenters = vtkCellCenters::New();
48 myTransformFilter = SALOME_TransformFilter::New();
51 VISU_VectorsPL::~VISU_VectorsPL(){
52 myGlyph->UnRegisterAllOutputs();
55 myCenters->UnRegisterAllOutputs();
58 myGlyphSource->UnRegisterAllOutputs();
59 myGlyphSource->Delete();
61 myConeSource->UnRegisterAllOutputs();
62 myConeSource->Delete();
64 myLineSource->UnRegisterAllOutputs();
65 myLineSource->Delete();
67 myTransformFilter->UnRegisterAllOutputs();
68 myTransformFilter->Delete();
71 void VISU_VectorsPL::ShallowCopy(VISU_PipeLine *thePipeLine){
72 VISU_DeformedShapePL::ShallowCopy(thePipeLine);
73 if(VISU_VectorsPL *aPipeLine = dynamic_cast<VISU_VectorsPL*>(thePipeLine)){
74 SetGlyphType(aPipeLine->GetGlyphType());
75 SetGlyphPos(aPipeLine->GetGlyphPos());
80 void VISU_VectorsPL::SetTransform(SALOME_Transform* theTransform){
81 myFieldTransform->SetSpaceTransform(theTransform);
82 myTransformFilter->SetTransform(theTransform);
83 myTransformFilter->Modified();
85 SALOME_Transform* VISU_VectorsPL::GetTransform(){
86 return myFieldTransform->GetSpaceTransform();
90 void VISU_VectorsPL::SetScale(float theScale) {
91 if(myScaleFactor == theScale) return;
92 myScaleFactor = theScale;
93 myGlyph->SetScaleFactor(myScaleFactor);
96 float VISU_VectorsPL::GetScale() {
97 return myGlyph->GetScaleFactor();
101 void VISU_VectorsPL::Init(){
102 VISU_DeformedShapePL::Init();
109 VISU_ScalarMapPL::THook* VISU_VectorsPL::DoHook(){
110 VISU::ToCellCenters(myTransformFilter,myCenters,myInput,myFieldTransform);
111 myGlyph->SetInput(myTransformFilter->GetOutput());
112 myGlyph->SetVectorModeToUseVector();
113 myGlyph->SetScaleModeToScaleByVector();
114 myGlyph->SetColorModeToColorByScalar();
115 return myGlyph->GetOutput();
119 void VISU_VectorsPL::Update(){
120 switch (myTypeGlyph) {
122 myGlyphSource->SetGlyphTypeToArrow();
123 myGlyphSource->SetFilled(0);
124 switch (myPosGlyph) {
126 myGlyphSource->SetCenter(0.5, 0.0, 0.0);
129 myGlyphSource->SetCenter(-0.5, 0.0, 0.0);
132 myGlyphSource->SetCenter(0.0, 0.0, 0.0);
134 // if(myPosGlyph == TAIL)
135 // myGlyphSource->SetCenter(0.5, 0.0, 0.0);
136 // else if(myPosGlyph == HEAD)
137 // myGlyphSource->SetCenter(-0.5, 0.0, 0.0);
138 myGlyph->SetSource(myGlyphSource->GetOutput());
143 if (myTypeGlyph == CONE2)
144 myConeSource->SetResolution(3);
146 myConeSource->SetResolution(7);
147 myConeSource->SetHeight(1.0);
148 myConeSource->SetRadius(.1);
150 switch (myPosGlyph) {
152 myConeSource->SetCenter(0.5, 0.0, 0.0);
155 myConeSource->SetCenter(-0.5, 0.0, 0.0);
158 myConeSource->SetCenter(0.0, 0.0, 0.0);
160 // if(myPosGlyph == TAIL)
161 // myConeSource->SetCenter(0.5, 0.0, 0.0);
162 // else if(myPosGlyph == HEAD)
163 // myConeSource->SetCenter(-0.5, 0.0, 0.0);
164 myGlyph->SetSource(myConeSource->GetOutput());
169 myGlyph->SetSource(myLineSource->GetOutput());
173 VISU_DeformedShapePL::Update();
177 void VISU_VectorsPL::SetMapScale(float theMapScale){
178 VISU_ScalarMapPL::SetMapScale(theMapScale);
180 myGlyph->SetScaleFactor(myScaleFactor*theMapScale);