ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/addin/vtkdisplay/src/vtkdisplay.cpp
Revision: 1116
Committed: Thu Jun 8 22:47:54 2023 UTC (2 years, 2 months ago) by francois
File size: 24953 byte(s)
Log Message:
ajout de clipping plane dans notre visualisateur

File Contents

# Content
1 // nUtil - An utility Library for gnurbs
2 // Copyright (C) 2008-2019 Eric Bechet
3 //
4 // See the LICENSE file for contributions and license information.
5 // Please report all bugs and problems to <bechet@cadxfem.org>.
6 //
7
8 #include "vtkdisplay.h"
9 #include "keyboardCallback.h"
10 #include "mousewheelforwardCallback.h"
11 #include "mousewheelbackwardCallback.h"
12
13 #include <vtkCellArray.h>
14 #include <vtkCellData.h>
15 #include <vtkDoubleArray.h>
16 #include <vtkPoints.h>
17 #include <vtkVertex.h>
18 #include <vtkLine.h>
19 #include <vtkTriangle.h>
20 #include <vtkQuad.h>
21 #include <vtkPolyData.h>
22 #include <vtkPolyDataMapper.h>
23 #include <vtkActor.h>
24 #include <vtkRenderWindow.h>
25 #include <vtkRenderer.h>
26 #include <vtkRenderWindowInteractor.h>
27 #include <vtkProperty.h>
28 #include <vtkCamera.h>
29 #include <vtkVectorText.h>
30 #include <vtkFollower.h>
31
32
33 #include "vtkLinearExtrusionFilter.h"
34 #include "vtkTextActor3D.h"
35 #include "vtkTextActor.h"
36 #include "vtkTextProperty.h"
37
38 void vtkdisplay::test(void)
39 {
40
41 double world_coord[3]={0.,0.,0.};
42 renderer->SetWorldPoint(world_coord[0], world_coord[1], world_coord[2], 1.0);
43 renderer->WorldToDisplay();
44 double *screen_coord = renderer->GetDisplayPoint();
45 vtkTextActor* text = vtkTextActor::New();
46 text->SetInput ( "VTK tutorial\nvtkTextActor!" );
47 vtkTextProperty* tprop = text->GetTextProperty();
48 tprop->SetFontFamilyToArial ();
49 // tprop->BoldOn();
50 // tprop->ShadowOn();
51 tprop->SetLineSpacing ( 1.0 );
52 tprop->SetFontSize ( 12 );
53 tprop->SetColor ( 1.0,0.0,0.0 );
54 // tprop->SetShadowOffset ( 2,2 );
55 text->SetDisplayPosition (screen_coord[0], screen_coord[1] );
56 renderer->AddActor2D ( text );
57 /* 3D text
58 // Create a vector text
59 vtkVectorText* vecText = vtkVectorText::New();
60 vecText->SetText ( "vtkVectorText" );
61
62 vtkLinearExtrusionFilter* extrude = vtkLinearExtrusionFilter::New();
63 extrude->SetInputConnection ( vecText->GetOutputPort() );
64 extrude->SetExtrusionTypeToNormalExtrusion();
65 extrude->SetVector ( 0, 0, 1 );
66 extrude->SetScaleFactor ( 0.5 );
67
68 vtkPolyDataMapper* txtMapper = vtkPolyDataMapper::New();
69 txtMapper->SetInputConnection ( extrude->GetOutputPort() );
70 vtkActor* txtActor = vtkActor::New();
71 txtActor->SetMapper ( txtMapper );
72 ren->AddActor ( txtActor );
73
74 */
75 }
76
77
78 vtkdisplay::vtkdisplay(color c,const char *nom):line(true),quad(true),triangle(true),vertice(true)
79 {
80 numero[0]=true;
81 numero[1]=true;
82 numero[2]=true;
83 renderer = vtkSmartPointer<vtkRenderer>::New();
84 renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
85 renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
86 interactorObserver = vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
87
88 renderWindow->AddRenderer(renderer);
89 if (nom!=NULL) renderWindow->SetWindowName(nom);
90 renderWindowInteractor->SetRenderWindow(renderWindow);
91 renderWindowInteractor->SetInteractorStyle(interactorObserver);
92 renderWindow->SetSize(800, 600);
93 renderWindow->SetAAFrames(4); // soft antialiasing
94 renderWindow->SetMultiSamples(4); // hardware antialiasing
95 renderWindow->PointSmoothingOn(); // points as circles
96 double r=c.R/255.;
97 double g=c.G/255.;
98 double b=c.B/255.;
99 renderer->SetBackground(r, g, b);
100
101
102
103 }
104
105 void vtkdisplay::display()
106 {
107 /* if (ncb)
108 {
109 ncb->draw();
110 init_data(*(ncb->get_data()));
111 }*/
112 renderer->ResetCamera();
113 renderer->GetActiveCamera()->ParallelProjectionOn();
114 renderWindow->Render();
115 keyboardCallback *keybcall = keyboardCallback::New(this);
116 renderWindowInteractor->AddObserver(vtkCommand::KeyPressEvent, keybcall);
117 mousewheelforwardCallback *mousewheelforwardcall=mousewheelforwardCallback::New(this);
118 renderWindowInteractor->AddObserver(vtkCommand::MouseWheelForwardEvent, mousewheelforwardcall);
119 mousewheelbackwardCallback *mousewheelbackwardcall=mousewheelbackwardCallback::New(this);
120 renderWindowInteractor->AddObserver(vtkCommand::MouseWheelBackwardEvent, mousewheelbackwardcall);
121
122 saveCameraDefault();
123 scaleactif=renderer->GetActiveCamera()->GetParallelScale();
124 double *ptr = renderer->GetActiveCamera()->GetClippingRange();
125 plan1=ptr[0];
126 plan2=ptr[1];
127 renderWindowInteractor->Start();
128 }
129
130 void vtkdisplay::init_data_vertices(const data_container & data)
131 {
132 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
133
134 for (int blk=0;blk<data.getnumproppoints();++blk)
135 {
136 color c=data.getcolorpoints(blk);
137 int last=(blk+1<data.getnumproppoints()) ? data.getindexpoints(blk+1) : data.nb_points();
138 // std::cout << blk << " " << data.getindexpoints(blk) << " " << last << std::endl ;
139 vtkSmartPointer<vtkCellArray> vertices = vtkSmartPointer<vtkCellArray>::New();
140 for (int i=data.getindexpoints(blk);i!=last;++i)
141 {
142 points->InsertNextPoint(data.get_point(i).pts.array());
143 vtkSmartPointer<vtkVertex> vertex = vtkSmartPointer<vtkVertex>::New();
144 vertex->GetPointIds()->InsertId(0,i);
145 vertices->InsertNextCell(vertex);
146 }
147 //Create a polydata to store everything in
148 vtkSmartPointer<vtkPolyData> verticesPolyData = vtkSmartPointer<vtkPolyData>::New();
149 //add the points to the dataset
150 verticesPolyData->SetPoints(points);
151 //add the lines to the dataset
152 verticesPolyData->SetVerts(vertices);
153 //setup actor and mapper
154 vtkSmartPointer<vtkPolyDataMapper> mapper_vertices = vtkSmartPointer<vtkPolyDataMapper>::New();
155 #if (VTK_MAJOR_VERSION>=6)
156 mapper_vertices->SetInputData(verticesPolyData);
157 #else
158 mapper_vertices->SetInput(verticesPolyData);
159 #endif
160 vtkSmartPointer<vtkActor> actor_vertices = vtkSmartPointer<vtkActor>::New();
161 double r=data.getcolorpoints(blk).R/255.;
162 double g=data.getcolorpoints(blk).G/255.;
163 double b=data.getcolorpoints(blk).B/255.;
164 actor_vertices->GetProperty()->SetColor(r,g,b);
165 actor_vertices->GetProperty()->SetOpacity(data.getcolorpoints(blk).A/255.);
166 actor_vertices->GetProperty()->SetPointSize(data.getproppoints(blk).pointsize);
167 actor_vertices->SetMapper(mapper_vertices);
168 renderer->AddActor(actor_vertices);
169 list_vertice.push_back(actor_vertices);
170 }
171
172
173
174 }
175 void vtkdisplay::init_data_texts(const data_container & data)
176 {
177 if (data.nb_texts(0)+data.nb_texts(1)+data.nb_texts(2)==0) return;
178 double xmin=1e308,ymin=1e308,zmin=1e308;
179 double xmax=-1e308,ymax=-1e308,zmax=-1e308;
180 for (int dim=0;dim<3;dim++)
181 {
182 int nb=data.nb_texts(dim);
183 for (int i=0;i<nb;i++)
184 {
185 if (data.get_text(dim,i).pts.x()<xmin) xmin=data.get_text(dim,i).pts.x();
186 if (data.get_text(dim,i).pts.y()<ymin) ymin=data.get_text(dim,i).pts.y();
187 if (data.get_text(dim,i).pts.z()<zmin) zmin=data.get_text(dim,i).pts.z();
188 if (data.get_text(dim,i).pts.x()>xmax) xmax=data.get_text(dim,i).pts.x();
189 if (data.get_text(dim,i).pts.y()>ymax) ymax=data.get_text(dim,i).pts.y();
190 if (data.get_text(dim,i).pts.z()>zmax) zmax=data.get_text(dim,i).pts.z();
191 }
192 }
193 int nb2=data.nb_points();
194 for (int i=0;i<nb2;i++)
195 {
196 if (data.get_point(i).pts.x()<xmin) xmin=data.get_point(i).pts.x();
197 if (data.get_point(i).pts.y()<xmin) ymin=data.get_point(i).pts.y();
198 if (data.get_point(i).pts.z()<xmin) zmin=data.get_point(i).pts.z();
199 if (data.get_point(i).pts.x()>xmax) xmax=data.get_point(i).pts.x();
200 if (data.get_point(i).pts.y()>ymax) ymax=data.get_point(i).pts.y();
201 if (data.get_point(i).pts.z()>zmax) zmax=data.get_point(i).pts.z();
202 }
203 int nb3=data.nb_lines();
204 for (int i=0;i<nb3;i++)
205 {
206 for (int dim=0;dim<2;dim++)
207 {
208 if (data.get_line(i).pts[dim].x()<xmin) xmin=data.get_line(i).pts[dim].x();
209 if (data.get_line(i).pts[dim].y()<ymin) ymin=data.get_line(i).pts[dim].y();
210 if (data.get_line(i).pts[dim].z()<zmin) zmin=data.get_line(i).pts[dim].z();
211 if (data.get_line(i).pts[dim].x()>xmax) xmax=data.get_line(i).pts[dim].x();
212 if (data.get_line(i).pts[dim].y()>ymax) ymax=data.get_line(i).pts[dim].y();
213 if (data.get_line(i).pts[dim].z()>zmax) zmax=data.get_line(i).pts[dim].z();
214 }
215 }
216 int nb4=data.nb_triangles();
217 for (int i=0;i<nb4;i++)
218 {
219 for (int dim=0;dim<3;dim++)
220 {
221 if (data.get_triangle(i).pts[dim].x()<xmin) xmin=data.get_triangle(i).pts[dim].x();
222 if (data.get_triangle(i).pts[dim].y()<ymin) ymin=data.get_triangle(i).pts[dim].y();
223 if (data.get_triangle(i).pts[dim].z()<zmin) zmin=data.get_triangle(i).pts[dim].z();
224 if (data.get_triangle(i).pts[dim].x()>xmax) xmax=data.get_triangle(i).pts[dim].x();
225 if (data.get_triangle(i).pts[dim].y()>ymax) ymax=data.get_triangle(i).pts[dim].y();
226 if (data.get_triangle(i).pts[dim].z()>zmax) zmax=data.get_triangle(i).pts[dim].z();
227 }
228 }
229 int nb5=data.nb_quads();
230 for (int i=0;i<nb5;i++)
231 {
232 for (int dim=0;dim<4;dim++)
233 {
234 if (data.get_quad(i).pts[dim].x()<xmin) xmin=data.get_quad(i).pts[dim].x();
235 if (data.get_quad(i).pts[dim].y()<ymin) ymin=data.get_quad(i).pts[dim].y();
236 if (data.get_quad(i).pts[dim].z()<zmin) zmin=data.get_quad(i).pts[dim].z();
237 if (data.get_quad(i).pts[dim].x()>xmax) xmax=data.get_quad(i).pts[dim].x();
238 if (data.get_quad(i).pts[dim].y()>ymax) ymax=data.get_quad(i).pts[dim].y();
239 if (data.get_quad(i).pts[dim].z()>zmax) zmax=data.get_quad(i).pts[dim].z();
240 }
241 }
242 double xec=xmax-xmin;
243 double yec=ymax-ymin;
244 double zec=zmax-zmin;
245 double scale=xec;
246
247 if (yec>scale) scale=yec;
248 if (zec>scale) scale=zec;
249
250 for (int dim=0;dim<3;dim++)
251 {
252 int nb=data.nb_texts(dim);
253 for (int i=0;i<nb;i++)
254 {
255 vtkSmartPointer<vtkVectorText> textSource =
256 vtkSmartPointer<vtkVectorText>::New();
257 textSource->SetText( data.get_text(dim,i).info.c_str() );
258
259
260 // Create a mapper
261 vtkSmartPointer<vtkPolyDataMapper> mapper =
262 vtkSmartPointer<vtkPolyDataMapper>::New();
263 mapper->SetInputConnection( textSource->GetOutputPort() );
264
265
266
267 // Create a subclass of vtkActor: a vtkFollower that remains facing the camera
268 vtkSmartPointer<vtkFollower> follower =
269 vtkSmartPointer<vtkFollower>::New();
270 follower->SetMapper( mapper );
271 follower->GetProperty()->SetColor( data.get_text_color(dim,i).R/255.,data.get_text_color(dim,i).G/255.,data.get_text_color(dim,i).B/255.); // red
272 follower->SetPosition(data.get_text(dim,i).pts.x(),data.get_text(dim,i).pts.y(),data.get_text(dim,i).pts.z()); // red
273 follower->SetScale(0.008333333*3.*scale); // red
274 renderer->AddActor( follower );
275 follower->SetCamera( renderer->GetActiveCamera() );
276 list_numero[dim].push_back(follower);
277 }
278 }
279 }
280
281 void vtkdisplay::init_data_lines(const data_container & data)
282 {
283 vtkSmartPointer<vtkPoints> linespoints = vtkSmartPointer<vtkPoints>::New();
284 for (int blk=0;blk<data.getnumproplines();++blk)
285 {
286 color c=data.getcolorlines(blk);
287 int last=(blk+1<data.getnumproplines()) ? data.getindexlines(blk+1) : data.nb_lines();
288 // std::cout << blk << " " << data.getindexlines(blk) << " " << last << std::endl ;
289 vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
290 for (int i=data.getindexlines(blk);i!=last;++i)
291 {
292 linespoints->InsertNextPoint(data.get_line(i).pts[0].array());
293 linespoints->InsertNextPoint(data.get_line(i).pts[1].array());
294 vtkSmartPointer<vtkLine> line = vtkSmartPointer<vtkLine>::New();
295 line->GetPointIds()->InsertId(0,i*2);
296 line->GetPointIds()->InsertId(1,i*2+1);
297 lines->InsertNextCell(line);
298 }
299 //Create a polydata to store everything in
300 vtkSmartPointer<vtkPolyData> linesPolyData = vtkSmartPointer<vtkPolyData>::New();
301 //add the points to the dataset
302 linesPolyData->SetPoints(linespoints);
303 //add the lines to the dataset
304 linesPolyData->SetLines(lines);
305 //setup actor and mapper
306 vtkSmartPointer<vtkPolyDataMapper> mapper_lines = vtkSmartPointer<vtkPolyDataMapper>::New();
307 #if (VTK_MAJOR_VERSION>=6)
308 mapper_lines->SetInputData(linesPolyData);
309 #else
310 mapper_lines->SetInput(linesPolyData);
311 #endif
312 vtkSmartPointer<vtkActor> actor_lines = vtkSmartPointer<vtkActor>::New();
313 double r=data.getcolorlines(blk).R/255.;
314 double g=data.getcolorlines(blk).G/255.;
315 double b=data.getcolorlines(blk).B/255.;
316 double a=data.getcolorlines(blk).A/255.;
317 actor_lines->GetProperty()->SetColor(r,g,b);
318 actor_lines->GetProperty()->SetOpacity(a);
319 actor_lines->GetProperty()->SetLineWidth(data.getproplines(blk).thickness);
320 actor_lines->SetMapper(mapper_lines);
321 renderer->AddActor(actor_lines);
322 list_line.push_back(actor_lines);
323 // renderer->ResetCamera();
324 }
325 }
326
327 void vtkdisplay::init_data_triangles(const data_container & data)
328 {
329 vtkSmartPointer<vtkPoints> trianglespoints = vtkSmartPointer<vtkPoints>::New();
330 for (int blk=0;blk<data.getnumproptriangles();++blk)
331 {
332 color c=data.getcolortriangles(blk);
333 int last=(blk+1<data.getnumproptriangles()) ? data.getindextriangles(blk+1) : data.nb_triangles();
334 // std::cout << blk << " " << data.getindextriangles(blk) << " " << last << std::endl ;
335 vtkSmartPointer<vtkCellArray> triangles = vtkSmartPointer<vtkCellArray>::New();
336 for (int i=data.getindextriangles(blk);i!=last;++i)
337 {
338 trianglespoints->InsertNextPoint(data.get_triangle(i).pts[0].array());
339 trianglespoints->InsertNextPoint(data.get_triangle(i).pts[1].array());
340 trianglespoints->InsertNextPoint(data.get_triangle(i).pts[2].array());
341 vtkSmartPointer<vtkTriangle> triangle = vtkSmartPointer<vtkTriangle>::New();
342 triangle->GetPointIds()->InsertId(0,i*3);
343 triangle->GetPointIds()->InsertId(1,i*3+1);
344 triangle->GetPointIds()->InsertId(2,i*3+2);
345 triangles->InsertNextCell(triangle);
346 }
347 //Create a polydata to store everything in
348 vtkSmartPointer<vtkPolyData> trianglesPolyData = vtkSmartPointer<vtkPolyData>::New();
349 //add the points to the dataset
350 trianglesPolyData->SetPoints(trianglespoints);
351 //add the triangles to the dataset
352 trianglesPolyData->SetPolys(triangles);
353 //setup actor and mapper
354 vtkSmartPointer<vtkPolyDataMapper> mapper_triangles = vtkSmartPointer<vtkPolyDataMapper>::New();
355 vtkSmartPointer<vtkActor> actor_triangles = vtkSmartPointer<vtkActor>::New();
356 double r=data.getcolortriangles(blk).R/255.;
357 double g=data.getcolortriangles(blk).G/255.;
358 double b=data.getcolortriangles(blk).B/255.;
359 double a=data.getcolortriangles(blk).A/255.;
360 actor_triangles->GetProperty()->SetColor(r,g,b);
361 actor_triangles->GetProperty()->SetOpacity(a);
362 #if (VTK_MAJOR_VERSION>=6)
363 mapper_triangles->SetInputData(trianglesPolyData);
364 #else
365 mapper_triangles->SetInput(trianglesPolyData);
366 #endif
367
368 actor_triangles->SetMapper(mapper_triangles);
369 if (data.getproptriangles(blk).edgeon)
370 {
371 actor_triangles->GetProperty()->EdgeVisibilityOn();
372 actor_triangles->GetProperty()->SetEdgeColor(data.getproptriangles(blk).edgecolor.R/255.,data.getproptriangles(blk).edgecolor.G/255.,data.getproptriangles(blk).edgecolor.B/255.);
373 actor_triangles->GetProperty()->SetLineWidth(data.getproptriangles(blk).edgethickness);
374 }
375 renderer->AddActor(actor_triangles);
376 list_triangle.push_back(actor_triangles);
377 }
378 }
379
380 void vtkdisplay::init_data_quads(const data_container & data)
381 {
382 vtkSmartPointer<vtkPoints> quadspoints = vtkSmartPointer<vtkPoints>::New();
383 for (int blk=0;blk<data.getnumpropquads();++blk)
384 {
385 color c=data.getcolorquads(blk);
386 int last=(blk+1<data.getnumpropquads()) ? data.getindexquads(blk+1) : data.nb_quads();
387 // std::cout << blk << " " << data.getindexquads(blk) << " " << last << std::endl ;
388 vtkSmartPointer<vtkCellArray> quads = vtkSmartPointer<vtkCellArray>::New();
389 for (int i=data.getindexquads(blk);i!=last;++i)
390 {
391 quadspoints->InsertNextPoint(data.get_quad(i).pts[0].array());
392 quadspoints->InsertNextPoint(data.get_quad(i).pts[1].array());
393 quadspoints->InsertNextPoint(data.get_quad(i).pts[2].array());
394 quadspoints->InsertNextPoint(data.get_quad(i).pts[3].array());
395 vtkSmartPointer<vtkQuad> quad = vtkSmartPointer<vtkQuad>::New();
396 quad->GetPointIds()->InsertId(0,i*4);
397 quad->GetPointIds()->InsertId(1,i*4+1);
398 quad->GetPointIds()->InsertId(2,i*4+2);
399 quad->GetPointIds()->InsertId(3,i*4+3);
400 quads->InsertNextCell(quad);
401 }
402 //Create a polydata to store everything in
403 vtkSmartPointer<vtkPolyData> quadsPolyData = vtkSmartPointer<vtkPolyData>::New();
404 //add the points to the dataset
405 quadsPolyData->SetPoints(quadspoints);
406 //add the quads to the dataset
407 quadsPolyData->SetPolys(quads);
408 //setup actor and mapper
409 vtkSmartPointer<vtkPolyDataMapper> mapper_quads = vtkSmartPointer<vtkPolyDataMapper>::New();
410 vtkSmartPointer<vtkActor> actor_quads = vtkSmartPointer<vtkActor>::New();
411 double r=data.getcolorquads(blk).R/255.;
412 double g=data.getcolorquads(blk).G/255.;
413 double b=data.getcolorquads(blk).B/255.;
414 double a=data.getcolorquads(blk).A/255.;
415 actor_quads->GetProperty()->SetColor(r,g,b);
416 actor_quads->GetProperty()->SetOpacity(a);
417
418 #if (VTK_MAJOR_VERSION>=6)
419 mapper_quads->SetInputData(quadsPolyData);
420 #else
421 mapper_quads->SetInput(quadsPolyData);
422 #endif
423 actor_quads->SetMapper(mapper_quads);
424 if (data.getpropquads(blk).edgeon)
425 {
426 actor_quads->GetProperty()->EdgeVisibilityOn();
427 actor_quads->GetProperty()->SetEdgeColor(data.getpropquads(blk).edgecolor.R/255.,data.getpropquads(blk).edgecolor.G/255.,data.getpropquads(blk).edgecolor.B/255.);
428 actor_quads->GetProperty()->SetLineWidth(data.getpropquads(blk).edgethickness);
429 }
430
431 renderer->AddActor(actor_quads);
432 list_quad.push_back(actor_quads);
433 }
434 }
435
436 void vtkdisplay::init_data(const data_container & data)
437 {
438 init_data_vertices(data);
439 init_data_lines(data);
440 init_data_triangles(data);
441 init_data_quads(data);
442 init_data_texts(data);
443 }
444
445 void vtkdisplay::init_data(const std::vector<data_container> &data)
446 {
447 for (int i=0;i<data.size();++i)
448 init_data(data[i]);
449 }
450
451
452
453 void vtkdisplay::mousewheelforwardCall(int x,int y)
454 {
455 double scale=renderer->GetActiveCamera()->GetParallelScale();
456 double facteur=scaleactif/scale;
457 scaleactif=scale;
458 for (int dim=0;dim<3;dim++)
459 {
460 for (int i=0;i<list_numero[dim].size();i++)
461 {
462 double *scaleactor=list_numero[dim][i]->GetScale();
463 list_numero[dim][i]->SetScale(*scaleactor/facteur);
464 }
465
466 }
467 renderWindow->Render();
468 }
469
470 void vtkdisplay::mousewheelbackwardCall(int x,int y)
471 {
472 double scale=renderer->GetActiveCamera()->GetParallelScale();
473 double facteur=scaleactif/scale;
474 scaleactif=scale;
475 for (int dim=0;dim<3;dim++)
476 {
477 for (int i=0;i<list_numero[dim].size();i++)
478 {
479 double *scaleactor=list_numero[dim][i]->GetScale();
480 list_numero[dim][i]->SetScale(*scaleactor/facteur);
481 }
482
483 }
484 renderWindow->Render();
485 }
486
487
488 void vtkdisplay::kbCallback(int key)
489 {
490 //std::cout << key << std::endl;
491 switch (key)
492 {
493 case 53:
494 {
495
496 vtkCamera * cam = renderer->GetActiveCamera();
497 cam->SetClippingRange( plan1, plan2 );
498 renderWindow->Render();
499
500 break;
501 }
502 case 56:
503 {
504 interactorObserver->AutoAdjustCameraClippingRangeOff();
505 vtkCamera * cam = renderer->GetActiveCamera();
506 double *ptr = cam->GetClippingRange();
507 double v1 = ptr[0]*1.1 - ptr[1]*0.1;
508 double v2 = ptr[1];
509 cam->SetClippingRange( v1, v2 );
510 renderWindow->Render();
511
512 break;
513 }
514 case 57:
515 {
516 interactorObserver->AutoAdjustCameraClippingRangeOff();
517 vtkCamera * cam = renderer->GetActiveCamera();
518 double *ptr = cam->GetClippingRange();
519 double v1 = ptr[0]*0.9 + ptr[1]*0.1;
520 double v2 = ptr[1];
521 cam->SetClippingRange( v1, v2 );
522 renderWindow->Render();
523
524 break;
525 }
526 case 114: //r
527 {
528 resetCamera();
529 break;
530 }
531 case 43:
532 {
533 for (int dim=0;dim<3;dim++)
534 {
535 for (int i=0;i<list_numero[dim].size();i++)
536 {
537 double *scaleactor=list_numero[dim][i]->GetScale();
538 list_numero[dim][i]->SetScale(*scaleactor*1.1);
539 }
540
541 }
542 renderWindow->Render();break;
543 }
544 case 45:
545 {
546 for (int dim=0;dim<3;dim++)
547 {
548 for (int i=0;i<list_numero[dim].size();i++)
549 {
550 double *scaleactor=list_numero[dim][i]->GetScale();
551 list_numero[dim][i]->SetScale(*scaleactor/1.1);
552 }
553
554 }
555 renderWindow->Render();break;
556 }
557 case 49:
558 {
559 for (int i=0;i<list_numero[0].size();i++)
560 {
561 if (numero[0]==true)
562 renderer->RemoveActor(list_numero[0][i]);
563 else
564 renderer->AddActor(list_numero[0][i]);
565
566 }
567 if (numero[0]==true) numero[0]=false; else numero[0]=true;
568 renderWindow->Render();
569 break;
570 }
571 case 52:
572 {
573 for (int i=0;i<list_numero[1].size();i++)
574 {
575 if (numero[1]==true)
576 renderer->RemoveActor(list_numero[1][i]);
577 else
578 renderer->AddActor(list_numero[1][i]);
579
580 }
581 if (numero[1]==true) numero[1]=false; else numero[1]=true;
582 renderWindow->Render();
583 break;
584 }
585 case 55:
586 {
587 for (int i=0;i<list_numero[2].size();i++)
588 {
589 if (numero[2]==true)
590 renderer->RemoveActor(list_numero[2][i]);
591 else
592 renderer->AddActor(list_numero[2][i]);
593
594 }
595 if (numero[2]==true) numero[2]=false; else numero[2]=true;
596 renderWindow->Render();
597 break;
598 }
599 case 118:
600 {
601 for (int i=0;i<list_vertice.size();i++)
602 {
603 if (vertice==true)
604 renderer->RemoveActor(list_vertice[i]);
605 else
606 renderer->AddActor(list_vertice[i]);
607
608 }
609 if (vertice==true) vertice=false; else vertice=true;
610 renderWindow->Render();
611 break;
612 }
613 case 116:
614 {
615 for (int i=0;i<list_triangle.size();i++)
616 {
617 if (triangle==true)
618 renderer->RemoveActor(list_triangle[i]);
619 else
620 renderer->AddActor(list_triangle[i]);
621
622 }
623 if (triangle==true) triangle=false; else triangle=true;
624 for (int i=0;i<list_quad.size();i++)
625 {
626 if (quad==true)
627 renderer->RemoveActor(list_quad[i]);
628 else
629 renderer->AddActor(list_quad[i]);
630
631 }
632 if (quad==true) quad=false; else quad=true;
633 renderWindow->Render();
634 break;
635 }
636 case 108:
637 {
638 for (int i=0;i<list_line.size();i++)
639 {
640 if (line==true)
641 renderer->RemoveActor(list_line[i]);
642 else
643 renderer->AddActor(list_line[i]);
644
645 }
646 if (line==true) line=false; else line=true;
647 renderWindow->Render();
648 break;
649 }
650 case 106:
651 {
652 double pos[3],focal[3],view[3];
653 vtkCamera * cam = renderer->GetActiveCamera();
654 cam->GetPosition(pos);
655 cam->GetFocalPoint(focal);
656 cam->GetViewUp(view);
657 double scale=cam->GetParallelScale();
658 FILE* out=fopen(".vtkdisplay","wt");
659 if (out==NULL) break;
660 fprintf(out,"%lf %lf %lf\n",pos[0],pos[1],pos[2]);
661 fprintf(out,"%lf %lf %lf\n",focal[0],focal[1],focal[2]);
662 fprintf(out,"%lf %lf %lf\n",view[0],view[1],view[2]);
663 fprintf(out,"%lf\n",scale);
664 fclose(out);
665 break;
666 }
667 case 107:
668 {
669 double pos[3],focal[3],view[3],scale;
670 FILE* in=fopen(".vtkdisplay","rt");
671 if (in==NULL) break;
672 char mess[255];
673 if (fgets(mess,255,in)==NULL) break;
674 if (sscanf(mess,"%lf %lf %lf",pos,pos+1,pos+2)!=3) break;
675 if (fgets(mess,255,in)==NULL) break;
676 if (sscanf(mess,"%lf %lf %lf",focal,focal+1,focal+2)!=3) break;
677 if (fgets(mess,255,in)==NULL) break;
678 if (sscanf(mess,"%lf %lf %lf",view,view+1,view+2)!=3) break;
679 if (fgets(mess,255,in)==NULL) break;
680 if (sscanf(mess,"%lf",&scale)!=1) break;
681 fclose(in);
682 vtkCamera * cam = renderer->GetActiveCamera();
683 cam->SetPosition(pos);
684 cam->SetFocalPoint(focal);
685 cam->SetViewUp(view);
686 cam->SetParallelScale(scale);
687 renderWindow->Render();
688 break;
689
690 }
691 }
692 }
693
694 void vtkdisplay::saveCameraDefault()
695 {
696 vtkCamera * cam = renderer->GetActiveCamera();
697 cam->GetPosition(cameraDefPosition);
698 cam->GetFocalPoint(cameraDefFocalPoint);
699 cam->GetViewUp(cameraDefViewUp);
700 }
701 void vtkdisplay::resetCamera()
702 {
703 vtkCamera * cam = renderer->GetActiveCamera();
704 cam->SetPosition(cameraDefPosition);
705 cam->SetFocalPoint(cameraDefFocalPoint);
706 cam->SetViewUp(cameraDefViewUp);
707 }
708