Developer documentation | Axl-2.5.1

axlActorPointSet.cpp
Go to the documentation of this file.
1 /* axlActorPointSet.cpp ---
2  *
3  * Author: Meriadeg Perrinel
4  * Copyright (C) 2008 - Meriadeg Perrinel, Inria.
5  * Created: Fri Dec 17 10:59:21 2010 (+0100)
6  * Version: $Id$
7  * Last-Updated: Wed Mar 16 21:51:16 2011 (+0100)
8  * By: Meriadeg Perrinel
9  * Update #: 23
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 #include "axlActorPointSet.h"
20 
21 #include <axlCore/axlPoint.h>
22 #include <axlCore/axlPointSet.h>
23 
24 #include <vtkActor.h>
25 #include <vtkCommand.h>
26 #include <vtkCellArray.h>
27 #include <vtkGlyph3D.h>
28 
29 #include <vtkIntArray.h>
30 #include <vtkLookupTable.h>
31 #include <vtkObjectFactory.h>
32 #include <vtkPoints.h>
33 #include <vtkPointData.h>
34 #include <vtkPolyData.h>
35 #include <vtkPolyDataMapper.h>
36 #include <vtkProperty.h>
37 #include <vtkSmartPointer.h>
38 #include <vtkSphereSource.h>
39 #include <vtkVertex.h>
40 
41 
42 // /////////////////////////////////////////////////////////////////
43 // axlActorPointSetPrivate
44 // /////////////////////////////////////////////////////////////////
45 
46 class axlActorPointSetPrivate
47 {
48 public:
49  axlPointSet *pointSet;
50 
51  vtkSmartPointer<vtkSphereSource> sphere;
52  vtkSmartPointer<vtkGlyph3D> glyph;
53 
54 };
55 
56 vtkCxxRevisionMacro(axlActorPointSet, "$Revision: 0.0.1 $");
58 
59 dtkAbstractData *axlActorPointSet::data(void)
60 {
61  return d->pointSet;
62 }
63 
64 
66 {
67  if(axlPointSet)
68  {
69  d->pointSet = axlPointSet;
70 
71  this->setPoints(vtkSmartPointer<vtkPoints>::New());
72  this->setMapper(vtkSmartPointer<vtkPolyDataMapper>::New());
73  this->setActor(vtkSmartPointer<vtkActor>::New());
74  this->setPolyData(vtkSmartPointer<vtkPolyData>::New());
75  this->setCellArray(vtkSmartPointer<vtkCellArray>::New());
76 
77 
78  vtkSmartPointer<vtkIntArray> scalarArray = vtkSmartPointer<vtkIntArray>::New();
79  scalarArray->SetName("mapperCollorArrayDefaultField");
80  scalarArray->SetNumberOfComponents(1);
81  scalarArray->SetNumberOfTuples(d->pointSet->numberOfPoints());
82 
83  vtkSmartPointer<vtkLookupTable> lookupTable = vtkSmartPointer<vtkLookupTable>::New();
84  lookupTable->SetRange(0.0, d->pointSet->numberOfPoints());
85  lookupTable->SetNumberOfTableValues(d->pointSet->numberOfPoints());
86 
87  for(int i = 0; i < d->pointSet->numberOfPoints(); i++)
88  {
89  this->getPoints()->InsertNextPoint(d->pointSet->value(i)->x(), d->pointSet->value(i)->y(), d->pointSet->value(i)->z());
90  scalarArray->SetTuple1(i, i);
91  //if(d->pointSet->value(i)->hasProperty("color"))
92 
93  }// all points are stocked into the vtkPoints
94  lookupTable->Build();
95 
96 
97  vtkSmartPointer<vtkVertex> currentVertex = vtkSmartPointer<vtkVertex>::New();
98 
99  for(int i = 0; i < d->pointSet->numberOfPoints(); i++)
100  {
101  currentVertex->GetPointIds()->SetId(0, i);
102  this->getCellArray()->InsertNextCell(currentVertex);
103  }
104 
105  if(!d->pointSet->isUniqueColor())
106  {
107  for(int i = 0; i < d->pointSet->numberOfPoints(); i++)
108  {
109  lookupTable->SetTableValue(i , d->pointSet->value(i)->color().redF(),d->pointSet->value(i)->color().greenF(), d->pointSet->value(i)->color().blueF(), 1.0);
110 
111  }
112 
113  }
114 
115 
116  this->getPolyData()->SetPoints(this->getPoints());
117  this->getPolyData()->SetVerts(this->getCellArray());
118 
119 
120 
121  if(!d->pointSet->isUniqueColor())
122  {
123  this->getPolyData()->GetPointData()->AddArray(scalarArray);
124  this->getPolyData()->GetPointData()->SetActiveScalars("mapperCollorArrayDefaultField");
125 
126  this->getMapper()->SetLookupTable(lookupTable);
127  this->getMapper()->SetInterpolateScalarsBeforeMapping(true);
128  this->getMapper()->UseLookupTableScalarRangeOn();
129  this->getMapper()->SetScalarModeToUsePointData();
130  }
131 
132 
133  // connection of data to actor
134  this->getMapper()->SetInput( this->getPolyData() );
135 
136  this->getActor()->SetMapper(this->getMapper());
137 
138  // glyph iniatialize
139 // if (d->pointSet->numberOfPoints() < 100)
140 // {
141 // d->sphere = vtkSmartPointer<vtkSphereSource>::New();
142 // d->sphere->SetPhiResolution(40);
143 // d->sphere->SetThetaResolution(40);
144 // d->sphere->SetRadius(0.1);
145 // d->glyph = vtkSmartPointer<vtkGlyph3D>::New();
146 // d->glyph->SetInput(this->getPolyData());
147 // d->glyph->SetSource(d->sphere->GetOutput());
148 // d->glyph->SetScaleModeToDataScalingOff();
149 
150 // this->getMapper()->SetInput( d->glyph->GetOutput());
151 // }
152  //d->glyph->SetScaleFactor(0.1);
153  if(d->pointSet->isUniqueColor())
154  {
155  QColor color = d->pointSet->color();
156  this->getActor()->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
157 
158  QString shader = d->pointSet->shader();
159  if(!shader.isEmpty())
160  this->setShader(shader);
161 
162  this->setOpacity(d->pointSet->opacity());
163  }
164 
165  this->setSize(d->pointSet->size());
166 
167  this->AddPart(this->getActor());
168 
169  }
170  else
171  qDebug()<< "no axlPointSet available";
172 
173 
174 }
175 
176 
178 {
179  this->onModeChanged(state);
180 
181  emit stateChanged(this->data(), state);
182 }
183 
185 {
186 
187  if(state == 0)
188  {
190  this->getActor()->SetPickable(1);
191 
192  if(axlAbstractData *data = dynamic_cast<axlAbstractData *>(this->data()))
193  {
194  QColor color = data->color();
195  this->getActor()->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
196  }
197 
198  }
199  else if(state == 1)
200  {
201 
203  this->getActor()->SetPickable(1);
204  vtkProperty *prop = this->getActor()->GetProperty();
205 
206  if(axlAbstractData *data = dynamic_cast<axlAbstractData *>(this->data()))
207  {
208  QColor color = data->color();
209  qreal *h = new qreal(0.0);
210  qreal *s = new qreal(0.0);
211  qreal *l = new qreal(0.0);
212  color.getHslF(h, s, l);
213  color.setHslF(*h, *s, *l + (1.0 - *l) / 2.0);
214  prop->SetColor(color.redF(), color.greenF(), color.blueF());
215  }
216 
217  }
218  else if(state == 2)
219  {
221  this->getActor()->SetPickable(0);
222  vtkProperty *prop = this->getActor()->GetProperty();
223  if(axlAbstractData *data = dynamic_cast<axlAbstractData *>(this->data()))
224  {
225  QColor color = data->color();
226  qreal *h = new qreal(0.0);
227  qreal *s = new qreal(0.0);
228  qreal *l = new qreal(0.0);
229  color.getHslF(h, s, l);
230  color.setHslF(*h, *s, *l + (1.0 - *l)/2.0);
231  prop->SetColor(color.redF(), color.greenF(), color.blueF());
232  }
233  }
234 
235  this->Modified();
236 }
237 
238 void axlActorPointSet::setSize(double size)
239 {
240  this->getActor()->GetProperty()->SetPointSize(size);
241 }
242 
243 axlActorPointSet::axlActorPointSet(void) : axlActor(), d(new axlActorPointSetPrivate)
244 {
245 
246 }
247 
249 {
250  delete d;
251 
252  d = NULL;
253 }
dtkAbstractData * data(void)
vtkSmartPointer< vtkCellArray > getCellArray(void)
Definition: axlActor.cpp:307
void setMode(int state)
void stateChanged(dtkAbstractData *data, int mode)
vtkSmartPointer< vtkPolyData > getPolyData(void)
Definition: axlActor.cpp:295
void onModeChanged(int state)
virtual void setState(int state)
Definition: axlActor.cpp:434
void setCellArray(vtkSmartPointer< vtkCellArray > cellArray)
Definition: axlActor.cpp:312
vtkCxxRevisionMacro(axlActorPointSet,"$Revision: 0.0.1 $")
vtkStandardNewMacro(axlActorPointSet)
vtkSmartPointer< vtkPoints > getPoints(void)
Definition: axlActor.cpp:275
void setPointSet(axlPointSet *axlPointsSet)
virtual void setShader(QString vsfile)
Definition: axlActor.cpp:517
virtual void setOpacity(double opacity)
Definition: axlActor.cpp:461
void setPolyData(vtkSmartPointer< vtkPolyData > polyData)
Definition: axlActor.cpp:300
void setMapper(vtkSmartPointer< vtkPolyDataMapper > mapper)
Definition: axlActor.cpp:332
void setActor(vtkSmartPointer< vtkActor > actor)
Definition: axlActor.cpp:322
vtkSmartPointer< vtkActor > getActor(void)
Definition: axlActor.cpp:317
vtkSmartPointer< vtkPolyDataMapper > getMapper(void)
Definition: axlActor.cpp:327
void setSize(double size)
Class axlAbstractData defines an API for all type of axel data.
void setPoints(vtkSmartPointer< vtkPoints > points)
Definition: axlActor.cpp:280