Developer documentation | Axl-2.5.1

axlActorCurveBSpline.cpp
Go to the documentation of this file.
1 /* axlActorCurveBSpline.cpp ---
2  *
3  * Author: Meriadeg Perrinel
4  * Copyright (C) 2008 - Meriadeg Perrinel, Inria.
5  * Created: Fri Dec 17 11:06:08 2010 (+0100)
6  * Version: $Id$
7  * Last-Updated: Mon Dec 17 15:03:49 2012 (+0100)
8  * By: Julien Wintz
9  * Update #: 71
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
20 #include "axlActorCurveBSpline.h"
21 #include "axlControlPointsWidget.h"
22 
24 
25 #include <vtkActor.h>
26 #include <vtkActorCollection.h>
27 #include <vtkCellArray.h>
28 #include <vtkCommand.h>
29 #include <vtkLine.h>
30 #include <vtkObjectFactory.h>
31 #include <vtkPoints.h>
32 #include <vtkPolyLine.h>
33 #include <vtkPolyData.h>
34 #include <vtkPolyDataMapper.h>
35 #include <vtkProperty.h>
36 #include <vtkSmartPointer.h>
37 #include <vtkTubeFilter.h>
38 
39 // /////////////////////////////////////////////////////////////////
40 // vtk related
41 // /////////////////////////////////////////////////////////////////
42 #if (VTK_MAJOR_VERSION <= 5)
43 vtkCxxRevisionMacro(axlActorCurveBSpline, "$Revision: 0.0.1 $");
44 #endif
45 
47 
48 // /////////////////////////////////////////////////////////////////
49 // axlActorCurveBSplinePrivate
50 // /////////////////////////////////////////////////////////////////
51 
52 class axlActorCurveBSplinePrivate
53 {
54 public:
55  axlAbstractCurveBSpline *splineCurve;
56  vtkSmartPointer<vtkTubeFilter> splineCurveTubeFilter;
57 };
58 
59 // /////////////////////////////////////////////////////////////////
60 // axlActorCurveBSpline
61 // /////////////////////////////////////////////////////////////////
62 axlActorCurveBSpline::axlActorCurveBSpline(void) : axlActorBSpline(), d(new axlActorCurveBSplinePrivate)
63 {
64  d->splineCurveTubeFilter = vtkSmartPointer<vtkTubeFilter>::New();
65  d->splineCurveTubeFilter->SetNumberOfSides(8);
66 }
67 
69 {
70  delete d;
71 
72  d = NULL;
73 }
74 
75 dtkAbstractData *axlActorCurveBSpline::data(void)
76 {
77  return d->splineCurve;
78 }
79 
80 void axlActorCurveBSpline::setData(dtkAbstractData *spline_curve1)
81 {
82  axlAbstractCurveBSpline *spline_curve = dynamic_cast<axlAbstractCurveBSpline *>(spline_curve1);
83  d->splineCurve = spline_curve;
84 
85  this->setPoints(vtkSmartPointer<vtkPoints>::New());
86  this->setMapper(vtkSmartPointer<vtkPolyDataMapper>::New());
87  this->setActor(vtkSmartPointer<vtkActor>::New());
88  this->setPolyData(vtkSmartPointer<vtkPolyData>::New());
89  this->setCellArray(vtkSmartPointer<vtkCellArray>::New());
90 
91  this->pointsUpdate();
92  this->polyDataUpdate();
93 
94  this->getPolyData()->SetPoints(this->getPoints());
95  this->getPolyData()->SetLines(this->getCellArray());
96 
97 #if (VTK_MAJOR_VERSION <= 5)
98  this->getMapper()->SetInput(this->getPolyData());
99 #else
100  this->getMapper()->SetInputData(this->getPolyData());
101 #endif
102  this->getActor()->SetMapper(this->getMapper());
103 
104  // add sphere param
105  //this->initCurrentPoint();
106 
107  if(!this->getObserver())
108  {
109  this->NewObserver();
110  this->setObserverData(d->splineCurve);
111  }
112 
113  this->AddPart(this->getActor());
114 
115  QColor color = d->splineCurve->color();
116  this->getActor()->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
117 
118  QString shader = d->splineCurve->shader();
119  if(!shader.isEmpty())
120  this->setShader(shader);
121 
122  // refresh the actor
123  this->onUpdateGeometry();
124 
125  // signals connecting
126  connect(d->splineCurve, SIGNAL(modifiedGeometry()), this, SLOT(onUpdateGeometry()));
127  connect(d->splineCurve, SIGNAL(modifiedProperty()), this, SLOT(onUpdateProperty()));
128 }
129 
131 {
132  this->pointsUpdate();
133  this->polyDataUpdate();
134 
135  this->onSamplingChanged();
136 
137 #if (VTK_MAJOR_VERSION <= 5)
138  d->splineCurveTubeFilter->SetInput(this->getPolyData());
139  this->getMapper()->SetInput(d->splineCurveTubeFilter->GetOutput());
140 #else
141  d->splineCurveTubeFilter->SetInputData(this->getPolyData());
142  this->getMapper()->SetInputData(d->splineCurveTubeFilter->GetOutput());
143 #endif
144  d->splineCurveTubeFilter->SetRadius(d->splineCurve->size());
145  d->splineCurveTubeFilter->Update();
146 }
147 
148 
150 {
151  //std::cout<<"axlActorCurveBSpline::pointsUpdate(void)"<<std::endl;
152 
153 //update rcoeff if the curve is a nurbs
154  if(d->splineCurve->rational())
155  {
156  d->splineCurve->updateRcoeff();
157 
158  }
159 
160  double start = d->splineCurve->startParam();
161  double end = d->splineCurve->endParam();
162  double paramCourant = start;
163 
164  vtkPoints *points = this->getPoints();
165 
166  axlPoint *pointCourant = new axlPoint;
167 
168  int n = d->splineCurve->numSamples();
169  points->SetNumberOfPoints(n);
170 
171  double interval = (double)(end-start) / (n -1);
172 
173  for (int i = 0; i < n-1; i++) {
174  d->splineCurve->eval(pointCourant, paramCourant);
175  points->SetPoint(i, pointCourant->coordinates());
176  paramCourant += interval;
177  }
178 
179  // boundary traitement
180  d->splineCurve->eval(pointCourant, end);
181  points->SetPoint(n - 1, pointCourant->coordinates());
182 
183  delete pointCourant;
184 }
185 
187 {
188  int n = d->splineCurve->numSamples();
189 
190  vtkSmartPointer<vtkLine> currentline = vtkSmartPointer<vtkLine>::New();
191  currentline->GetPointIds()->SetNumberOfIds(2);
192 
193  for(int i= 0; i < n - 1; i++) {
194  currentline->GetPointIds()->SetId(0 , i);
195  currentline->GetPointIds()->SetId(1 , i + 1);
196  this->getCellArray()->InsertNextCell(currentline);
197  }
198 }
199 
201 {
202  if (d->splineCurve) {
203  // delete current vtkPoint and vtkCellArray
204  this->getMapper()->RemoveAllInputs();
205  this->getPolyData()->Initialize();
206 
207  // delete current vtkPoint and vtkCellArray
208  this->getPoints()->Reset();
209  this->getCellArray()->Reset();
210 
211  this->getPoints()->Squeeze();
212  this->getCellArray()->Squeeze();
213 
214  this->pointsUpdate();
215  this->polyDataUpdate();
216 
217  this->getPolyData()->SetPoints(this->getPoints());
218  this->getPolyData()->SetLines(this->getCellArray());
219 
220 //#if (VTK_MAJOR_VERSION <= 5)
221 // this->getMapper()->SetInput(this->getPolyData());
222 //#else
223 // this->getMapper()->SetInputData(this->getPolyData());
224 //#endif
225 #if (VTK_MAJOR_VERSION <= 5)
226  d->splineCurveTubeFilter->SetInput(this->getPolyData());
227  this->getMapper()->SetInput(d->splineCurveTubeFilter->GetOutput());
228 #else
229  d->splineCurveTubeFilter->SetInputData(this->getPolyData());
230  this->getMapper()->SetInputData(d->splineCurveTubeFilter->GetOutput());
231 #endif
232 
233  d->splineCurveTubeFilter->SetRadius(d->splineCurve->size());
234  d->splineCurveTubeFilter->Update();
235 
236  if (d->splineCurve->fields().count() != 0)
237  d->splineCurve->touchField();
238  }
239 
240 }
241 
243 {
244 
245 #if (VTK_MAJOR_VERSION <= 5)
246  d->splineCurveTubeFilter->SetInput(this->getPolyData());
247  this->getMapper()->SetInput(d->splineCurveTubeFilter->GetOutput());
248 #else
249  d->splineCurveTubeFilter->SetInputData(this->getPolyData());
250  this->getMapper()->SetInputData(d->splineCurveTubeFilter->GetOutput());
251 #endif
252 
253  d->splineCurveTubeFilter->SetRadius(radius);
254 // d->splineCurveTubeFilter->SetRadius(radius * side);
255  d->splineCurveTubeFilter->Update();
256 
257  if (this->getControlPoints())
258  this->getControlPoints()->SetControlPointRadius(radius);
259 }
260 
262 {
263  return d->splineCurveTubeFilter->GetOutput();
264 }
265 
267 {
268  return axlActorCurveBSpline::New();
269 }
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
vtkSmartPointer< vtkCellArray > getCellArray(void)
Definition: axlActor.cpp:307
virtual axlControlPointsWidget * getControlPoints(void)
vtkCxxRevisionMacro(axlActorCurveBSpline,"$Revision: 0.0.1 $")
double * coordinates(void) const
Returns coordinates of this point.
Definition: axlPoint.cpp:445
vtkStandardNewMacro(axlActorCurveBSpline)
vtkSmartPointer< vtkPolyData > getPolyData(void)
Definition: axlActor.cpp:295
virtual void setData(dtkAbstractData *spline_curve1)
void setCellArray(vtkSmartPointer< vtkCellArray > cellArray)
Definition: axlActor.cpp:312
virtual void onSamplingChanged(void)
virtual void onTubeFilterRadiusChanged(double radius)
static axlActorCurveBSpline * New(void)
vtkSmartPointer< vtkPoints > getPoints(void)
Definition: axlActor.cpp:275
virtual void setShader(QString vsfile)
Definition: axlActor.cpp:517
void setPolyData(vtkSmartPointer< vtkPolyData > polyData)
Definition: axlActor.cpp:300
void setMapper(vtkSmartPointer< vtkPolyDataMapper > mapper)
Definition: axlActor.cpp:332
dtkAbstractData * data(void)
vtkPolyData * getCurveMapperInput(void)
void setActor(vtkSmartPointer< vtkActor > actor)
Definition: axlActor.cpp:322
vtkSmartPointer< vtkActor > getActor(void)
Definition: axlActor.cpp:317
virtual void onUpdateProperty(void)
vtkSmartPointer< vtkPolyDataMapper > getMapper(void)
Definition: axlActor.cpp:327
void setObserverData(dtkAbstractData *data)
Definition: axlActor.cpp:424
axlActorControlPolygonObserver * getObserver(void)
Definition: axlActor.cpp:366
void SetControlPointRadius(double cpSize)
void NewObserver(void)
Definition: axlActor.cpp:386
void setPoints(vtkSmartPointer< vtkPoints > points)
Definition: axlActor.cpp:280
axlAbstractActor * createAxlActorCurveBSpline(void)