@@ -170,11 +170,15 @@ void vtkViewCubeActorHighlightCallback::Execute (vtkObject* caller, unsigned lon
170
170
171
171
// ====================================== LA CLASSE vtkViewCubeActor ======================================
172
172
173
+ // Couleur des faces du cube : gris clair.
174
+ static const unsigned char gray = (unsigned char )(3 . * 255 . / 4 .);
175
+
176
+
173
177
vtkViewCubeActor::vtkViewCubeActor ( )
174
- : vtkPropAssembly ( ), Renderer (0 ), DrivenRenderer (0 ), CubePolyData ( ), HighlightPolyData ( ), CubeActor ( ), HighlightActor ( ), CubePolyDataMapper ( ), HighlightPolyDataMapper ( ),
178
+ : vtkPropAssembly ( ), Renderer (0 ), DrivenRenderer (0 ), CubePolyData ( ), CubeActor ( ), CubePolyDataMapper ( ),
175
179
CellPicker ( ), LastPickedFace ((unsigned char )-1), HighlightedFace ((unsigned char )-1),
176
180
XPlusVectorText ( ), XMinusVectorText ( ), YPlusVectorText ( ), YMinusVectorText ( ), ZPlusVectorText ( ), ZMinusVectorText ( ),
177
- XPlusActor ( ), XMinusActor ( ), YPlusActor ( ), YMinusActor ( ), ZPlusActor ( ), ZMinusActor ( ), ViewUpVectors ( ),
181
+ XPlusActor ( ), XMinusActor ( ), YPlusActor ( ), YMinusActor ( ), ZPlusActor ( ), ZMinusActor ( ), ColorsVectors ( ), ViewUpVectors ( ),
178
182
Transform (0 )
179
183
{
180
184
CubePolyData = vtkSmartPointer<vtkPolyData>::New ( );
@@ -185,16 +189,15 @@ vtkViewCubeActor::vtkViewCubeActor ( )
185
189
assert (0 != CubeActor.Get ( ));
186
190
assert (0 != CubePolyDataMapper.Get ( ));
187
191
CubePolyData->Initialize ( );
188
- HighlightPolyData = vtkSmartPointer<vtkPolyData>::New ( );
189
- HighlightActor = vtkSmartPointer<vtkActor>::New ( );
190
- HighlightPolyDataMapper = vtkSmartPointer<vtkPolyDataMapper>::New ( );
191
- assert (0 != HighlightPolyData.Get ( ));
192
- assert (0 != HighlightActor.Get ( ));
193
- assert (0 != HighlightPolyDataMapper.Get ( ));
194
- HighlightPolyData->Initialize ( );
192
+ // Les couleurs des faces du cube : grises, sauf celle pointée par la souris (rouge) :
193
+ ColorsVectors = vtkSmartPointer<vtkUnsignedCharArray>::New ( );
194
+ ColorsVectors->SetName (" Colors" );
195
+ ColorsVectors->SetNumberOfComponents (3 );
196
+ // Les directions vers le haut :
195
197
ViewUpVectors = vtkSmartPointer<vtkDoubleArray>::New ( );
196
198
ViewUpVectors->SetName (" ViewUp" );
197
199
ViewUpVectors->SetNumberOfComponents (3 );
200
+ // Les points du cube :
198
201
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New ( );
199
202
assert (0 != points.Get ( ));
200
203
points->SetNumberOfPoints (24 );
@@ -237,7 +240,6 @@ vtkViewCubeActor::vtkViewCubeActor ( )
237
240
points->SetPoint (22 , j2, j2, length);
238
241
points->SetPoint (23 , j1 , j2, length);
239
242
CubePolyData->SetPoints (points);
240
- HighlightPolyData->SetPoints (points);
241
243
242
244
vtkCellArray* cellArray = vtkCellArray::New ( );
243
245
vtkIdTypeArray* idsArray = vtkIdTypeArray::New ( );
@@ -251,72 +253,97 @@ vtkViewCubeActor::vtkViewCubeActor ( )
251
253
size_t pos = 0 ;
252
254
cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 0 ; cellsPtr [pos++] = 1 ; cellsPtr [pos++] = 2 ; cellsPtr [pos++] = 3 ; // Bas
253
255
ViewUpVectors->InsertNextTuple3 (0 ., 0 ., 1 .);
256
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
254
257
cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 5 ; cellsPtr [pos++] = 6 ; cellsPtr [pos++] = 7 ; // Droite
255
258
ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
259
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
256
260
cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 8 ; cellsPtr [pos++] = 9 ; cellsPtr [pos++] = 10 ; cellsPtr [pos++] = 11 ; // Haut
257
261
ViewUpVectors->InsertNextTuple3 (0 ., 0 ., 1 .);
262
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
258
263
cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 15 ; cellsPtr [pos++] = 14 ; cellsPtr [pos++] = 13 ; cellsPtr [pos++] = 12 ; // Gauche
259
264
ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
265
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
260
266
cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 19 ; cellsPtr [pos++] = 18 ; cellsPtr [pos++] = 17 ; cellsPtr [pos++] = 16 ; // Arrière
261
267
ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
268
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
262
269
cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 20 ; cellsPtr [pos++] = 21 ; cellsPtr [pos++] = 22 ; cellsPtr [pos++] = 23 ; // Avant
263
270
ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
271
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
264
272
cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 16 ; cellsPtr [pos++] = 17 ; cellsPtr [pos++] = 1 ; cellsPtr [pos++] = 0 ; // Bas-Ar
265
273
ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
274
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
266
275
cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 1 ; cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 7 ; cellsPtr [pos++] = 2 ; // Bas-D
267
276
ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
277
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
268
278
cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 3 ; cellsPtr [pos++] = 2 ; cellsPtr [pos++] = 21 ; cellsPtr [pos++] = 20 ; // Bas-Av
269
279
ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
280
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
270
281
cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 12 ; cellsPtr [pos++] = 0 ; cellsPtr [pos++] = 3 ; cellsPtr [pos++] = 15 ; // Bas-G
271
282
ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
283
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
272
284
cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 18 ; cellsPtr [pos++] = 19 ; cellsPtr [pos++] = 9 ; cellsPtr [pos++] = 8 ; // Haut-Ar
273
285
ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
286
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
274
287
cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 5 ; cellsPtr [pos++] = 8 ; cellsPtr [pos++] = 11 ; cellsPtr [pos++] = 6 ; // Haut-D
275
288
ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
289
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
276
290
cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 11 ; cellsPtr [pos++] = 10 ; cellsPtr [pos++] = 23 ; cellsPtr [pos++] = 22 ; // Haut-Av
277
291
ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
292
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
278
293
cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 9 ; cellsPtr [pos++] = 13 ; cellsPtr [pos++] = 14 ; cellsPtr [pos++] = 10 ; // Haut-G
279
294
ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
295
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
280
296
cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 18 ; cellsPtr [pos++] = 5 ; cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 17 ; // Ar-D
281
297
ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
298
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
282
299
cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 7 ; cellsPtr [pos++] = 6 ; cellsPtr [pos++] = 22 ; cellsPtr [pos++] = 21 ; // Av-D
283
300
ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
301
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
284
302
cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 16 ; cellsPtr [pos++] = 12 ; cellsPtr [pos++] = 13 ; cellsPtr [pos++] = 19 ; // Ar-G
285
303
ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
304
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
286
305
cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 14 ; cellsPtr [pos++] = 15 ; cellsPtr [pos++] = 20 ; cellsPtr [pos++] = 23 ; // Av-G
287
306
ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
307
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
288
308
cellsPtr [pos++] = 3 ; cellsPtr [pos++] = 10 ; cellsPtr [pos++] = 14 ; cellsPtr [pos++] = 23 ; // Av-H-G
289
309
ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
310
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
290
311
cellsPtr [pos++] = 3 ; cellsPtr [pos++] = 22 ; cellsPtr [pos++] = 6 ; cellsPtr [pos++] = 11 ; // Av-H-D
291
312
ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
313
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
292
314
cellsPtr [pos++] = 3 ; cellsPtr [pos++] = 3 ; cellsPtr [pos++] = 20 ; cellsPtr [pos++] = 15 ; // Av-B-G
293
315
ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
316
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
294
317
cellsPtr [pos++] = 3 ; cellsPtr [pos++] = 2 ; cellsPtr [pos++] = 7 ; cellsPtr [pos++] = 21 ; // Av-B-D
295
318
ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
319
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
296
320
cellsPtr [pos++] = 3 ; cellsPtr [pos++] = 19 ; cellsPtr [pos++] = 13 ; cellsPtr [pos++] = 9 ; // Ar-H-G
297
321
ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
322
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
298
323
cellsPtr [pos++] = 3 ; cellsPtr [pos++] = 8 ; cellsPtr [pos++] = 5 ; cellsPtr [pos++] = 18 ; // Ar-H-D
299
324
ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
325
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
300
326
cellsPtr [pos++] = 3 ; cellsPtr [pos++] = 12 ; cellsPtr [pos++] = 16 ; cellsPtr [pos++] = 0 ; // Ar-B-G
301
327
ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
328
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
302
329
cellsPtr [pos++] = 3 ; cellsPtr [pos++] = 17 ; cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 7 ; // Ar-B-D
303
330
ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
331
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
304
332
cellArray->SetCells (6 + 12 + 8 , idsArray);
305
333
CubePolyData->SetPolys (cellArray);
334
+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
306
335
idsArray->Delete ( ); idsArray = 0 ;
307
336
cellArray->Delete ( ); cellArray = 0 ;
337
+
308
338
// points->Delete ( ); points = 0;
309
339
CubePolyDataMapper->SetInputData (CubePolyData);
310
- CubePolyDataMapper->ScalarVisibilityOff ( );
340
+ // CubePolyDataMapper->ScalarVisibilityOff ( );
341
+ CubePolyDataMapper->ScalarVisibilityOn ( );
342
+ CubePolyData->GetCellData ( )->SetScalars (ColorsVectors);
311
343
CubeActor->SetMapper (CubePolyDataMapper);
312
- CubeActor->GetProperty ( )->SetColor (.75 , .75 , .75 );
344
+ // CubeActor->GetProperty ( )->SetColor (.75, .75, .75);
313
345
CubeActor->PickableOn ( );
314
346
AddPart (CubeActor);
315
- HighlightPolyDataMapper->SetInputData (HighlightPolyData);
316
- HighlightPolyDataMapper->ScalarVisibilityOff ( );
317
- HighlightActor->SetMapper (HighlightPolyDataMapper);
318
- HighlightActor->GetProperty ( )->SetColor (1 ., 0 ., 0 .);
319
- HighlightActor->PickableOff ( );
320
347
321
348
XPlusVectorText = vtkSmartPointer<vtkVectorText>::New ( );
322
349
XMinusVectorText = vtkSmartPointer<vtkVectorText>::New ( );
@@ -410,10 +437,10 @@ vtkViewCubeActor::vtkViewCubeActor ( )
410
437
411
438
412
439
vtkViewCubeActor::vtkViewCubeActor (const vtkViewCubeActor&)
413
- : vtkPropAssembly ( ), Renderer (0 ), DrivenRenderer (0 ), CubePolyData ( ), HighlightPolyData ( ), CubeActor ( ), HighlightActor ( ), CubePolyDataMapper ( ), HighlightPolyDataMapper ( ),
440
+ : vtkPropAssembly ( ), Renderer (0 ), DrivenRenderer (0 ), CubePolyData ( ), CubeActor ( ), CubePolyDataMapper ( ),
414
441
CellPicker ( ), LastPickedFace ((unsigned char )-1), HighlightedFace ((unsigned char )-1),
415
442
XPlusVectorText ( ), XMinusVectorText ( ), YPlusVectorText ( ), YMinusVectorText ( ), ZPlusVectorText ( ), ZMinusVectorText ( ),
416
- XPlusActor ( ), XMinusActor ( ), YPlusActor ( ), YMinusActor ( ), ZPlusActor ( ), ZMinusActor ( ),
443
+ XPlusActor ( ), XMinusActor ( ), YPlusActor ( ), YMinusActor ( ), ZPlusActor ( ), ZMinusActor ( ), ColorsVectors ( ), ViewUpVectors ( ),
417
444
Transform (0 )
418
445
{
419
446
assert (0 && " vtkViewCubeActor copy constructor is not allowed." );
@@ -504,13 +531,11 @@ void vtkViewCubeActor::SetTransform (vtkTransform* transform)
504
531
while (0 != (property = collection->GetNextProp ( )))
505
532
{
506
533
vtkActor* actor = vtkActor::SafeDownCast (property);
507
- if (( 0 != actor) && (actor != HighlightActor) )
534
+ if (0 != actor)
508
535
{
509
536
actor->SetUserTransform (Transform);
510
537
} // if (0 != actor)
511
538
} // while (0 != (property = collection->GetNextProp ( )))
512
- if (0 != HighlightActor)
513
- HighlightActor->SetUserTransform (Transform);
514
539
} // vtkViewCubeActor::SetTransform
515
540
516
541
@@ -612,40 +637,25 @@ void vtkViewCubeActor::HighlightCallback (int x, int y)
612
637
if ((0 == CellPicker.Get ( )) || (0 == Renderer) || (0 == DrivenRenderer))
613
638
return ;
614
639
assert (0 != CubePolyData.Get ( ));
615
- assert (0 != HighlightPolyData.Get ( ));
616
- assert (0 != HighlightActor.Get ( ));
617
640
641
+ CubePolyData->GetCellData ( )->SetActiveScalars (" Colors" );
618
642
if (0 != CellPicker->Pick (x, y, 0 , Renderer))
619
643
{
620
644
if (HighlightedFace == CellPicker->GetCellId ( ))
621
645
return ;
622
-
646
+
623
647
if ((unsigned char )-1 != HighlightedFace)
624
648
{
625
- RemovePart (HighlightActor );
649
+ ColorsVectors-> SetTuple3 (HighlightedFace, gray, gray, gray );
626
650
} // if ((unsigned char)-1 != HighlightedFace)
627
651
HighlightedFace = CellPicker->GetCellId ( );
628
- vtkIdType npts = 0 ;
629
- vtkIdType* pts = 0 ;
630
- CubePolyData->GetCellPoints (CellPicker->GetCellId ( ), npts, pts);
631
- if (0 == HighlightPolyData->GetNumberOfCells ( ))
632
- {
633
- HighlightPolyData->Allocate (1 );
634
- HighlightPolyData->InsertNextCell (VTK_POLYGON, npts, pts);
635
- } // if (0 == HighlightPolyData->GetNumberOfCells ( ))
636
- else
637
- {
638
- HighlightPolyData->ReplaceCell (0 , npts, pts);
639
- HighlightPolyData->Modified ( );
640
- } // if (0 == HighlightPolyData->GetNumberOfCells ( ))
641
-
642
- AddPart (HighlightActor);
652
+ ColorsVectors->SetTuple3 (HighlightedFace, 255 , 0 , 0 );
643
653
} // if (0 != CellPicker->Pick (x, y, 0, Renderer))
644
654
else
645
655
{
646
656
if ((unsigned char )-1 != HighlightedFace)
647
657
{
648
- RemovePart (HighlightActor );
658
+ ColorsVectors-> SetTuple3 (HighlightedFace, gray, gray, gray );
649
659
} // if ((unsigned char)-1 != HighlightedFace)
650
660
HighlightedFace = (unsigned char )-1 ;
651
661
} // else if (0 != CellPicker->Pick (x, y, 0, Renderer))
0 commit comments