@@ -170,11 +170,15 @@ void vtkViewCubeActorHighlightCallback::Execute (vtkObject* caller, unsigned lon
170170
171171// ====================================== LA CLASSE vtkViewCubeActor ======================================
172172
173+ // Couleur des faces du cube : gris clair.
174+ static const unsigned char gray = (unsigned char )(3 . * 255 . / 4 .);
175+
176+
173177vtkViewCubeActor::vtkViewCubeActor ( )
174- : vtkPropAssembly ( ), Renderer (0 ), DrivenRenderer (0 ), CubePolyData ( ), HighlightPolyData ( ), CubeActor ( ), HighlightActor ( ), CubePolyDataMapper ( ), HighlightPolyDataMapper ( ),
178+ : vtkPropAssembly ( ), Renderer (0 ), DrivenRenderer (0 ), CubePolyData ( ), CubeActor ( ), CubePolyDataMapper ( ),
175179 CellPicker ( ), LastPickedFace ((unsigned char )-1), HighlightedFace ((unsigned char )-1),
176180 XPlusVectorText ( ), XMinusVectorText ( ), YPlusVectorText ( ), YMinusVectorText ( ), ZPlusVectorText ( ), ZMinusVectorText ( ),
177- XPlusActor ( ), XMinusActor ( ), YPlusActor ( ), YMinusActor ( ), ZPlusActor ( ), ZMinusActor ( ), ViewUpVectors ( ),
181+ XPlusActor ( ), XMinusActor ( ), YPlusActor ( ), YMinusActor ( ), ZPlusActor ( ), ZMinusActor ( ), ColorsVectors ( ), ViewUpVectors ( ),
178182 Transform (0 )
179183{
180184 CubePolyData = vtkSmartPointer<vtkPolyData>::New ( );
@@ -185,16 +189,15 @@ vtkViewCubeActor::vtkViewCubeActor ( )
185189 assert (0 != CubeActor.Get ( ));
186190 assert (0 != CubePolyDataMapper.Get ( ));
187191 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 :
195197 ViewUpVectors = vtkSmartPointer<vtkDoubleArray>::New ( );
196198 ViewUpVectors->SetName (" ViewUp" );
197199 ViewUpVectors->SetNumberOfComponents (3 );
200+ // Les points du cube :
198201 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New ( );
199202 assert (0 != points.Get ( ));
200203 points->SetNumberOfPoints (24 );
@@ -237,7 +240,6 @@ vtkViewCubeActor::vtkViewCubeActor ( )
237240 points->SetPoint (22 , j2, j2, length);
238241 points->SetPoint (23 , j1, j2, length);
239242 CubePolyData->SetPoints (points);
240- HighlightPolyData->SetPoints (points);
241243
242244 vtkCellArray* cellArray = vtkCellArray::New ( );
243245 vtkIdTypeArray* idsArray = vtkIdTypeArray::New ( );
@@ -251,72 +253,97 @@ vtkViewCubeActor::vtkViewCubeActor ( )
251253 size_t pos = 0 ;
252254 cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 0 ; cellsPtr [pos++] = 1 ; cellsPtr [pos++] = 2 ; cellsPtr [pos++] = 3 ; // Bas
253255 ViewUpVectors->InsertNextTuple3 (0 ., 0 ., 1 .);
256+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
254257 cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 5 ; cellsPtr [pos++] = 6 ; cellsPtr [pos++] = 7 ; // Droite
255258 ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
259+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
256260 cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 8 ; cellsPtr [pos++] = 9 ; cellsPtr [pos++] = 10 ; cellsPtr [pos++] = 11 ; // Haut
257261 ViewUpVectors->InsertNextTuple3 (0 ., 0 ., 1 .);
262+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
258263 cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 15 ; cellsPtr [pos++] = 14 ; cellsPtr [pos++] = 13 ; cellsPtr [pos++] = 12 ; // Gauche
259264 ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
265+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
260266 cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 19 ; cellsPtr [pos++] = 18 ; cellsPtr [pos++] = 17 ; cellsPtr [pos++] = 16 ; // Arrière
261267 ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
268+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
262269 cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 20 ; cellsPtr [pos++] = 21 ; cellsPtr [pos++] = 22 ; cellsPtr [pos++] = 23 ; // Avant
263270 ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
271+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
264272 cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 16 ; cellsPtr [pos++] = 17 ; cellsPtr [pos++] = 1 ; cellsPtr [pos++] = 0 ; // Bas-Ar
265273 ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
274+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
266275 cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 1 ; cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 7 ; cellsPtr [pos++] = 2 ; // Bas-D
267276 ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
277+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
268278 cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 3 ; cellsPtr [pos++] = 2 ; cellsPtr [pos++] = 21 ; cellsPtr [pos++] = 20 ; // Bas-Av
269279 ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
280+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
270281 cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 12 ; cellsPtr [pos++] = 0 ; cellsPtr [pos++] = 3 ; cellsPtr [pos++] = 15 ; // Bas-G
271282 ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
283+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
272284 cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 18 ; cellsPtr [pos++] = 19 ; cellsPtr [pos++] = 9 ; cellsPtr [pos++] = 8 ; // Haut-Ar
273285 ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
286+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
274287 cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 5 ; cellsPtr [pos++] = 8 ; cellsPtr [pos++] = 11 ; cellsPtr [pos++] = 6 ; // Haut-D
275288 ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
289+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
276290 cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 11 ; cellsPtr [pos++] = 10 ; cellsPtr [pos++] = 23 ; cellsPtr [pos++] = 22 ; // Haut-Av
277291 ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
292+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
278293 cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 9 ; cellsPtr [pos++] = 13 ; cellsPtr [pos++] = 14 ; cellsPtr [pos++] = 10 ; // Haut-G
279294 ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
295+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
280296 cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 18 ; cellsPtr [pos++] = 5 ; cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 17 ; // Ar-D
281297 ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
298+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
282299 cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 7 ; cellsPtr [pos++] = 6 ; cellsPtr [pos++] = 22 ; cellsPtr [pos++] = 21 ; // Av-D
283300 ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
301+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
284302 cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 16 ; cellsPtr [pos++] = 12 ; cellsPtr [pos++] = 13 ; cellsPtr [pos++] = 19 ; // Ar-G
285303 ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
304+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
286305 cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 14 ; cellsPtr [pos++] = 15 ; cellsPtr [pos++] = 20 ; cellsPtr [pos++] = 23 ; // Av-G
287306 ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
307+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
288308 cellsPtr [pos++] = 3 ; cellsPtr [pos++] = 10 ; cellsPtr [pos++] = 14 ; cellsPtr [pos++] = 23 ; // Av-H-G
289309 ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
310+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
290311 cellsPtr [pos++] = 3 ; cellsPtr [pos++] = 22 ; cellsPtr [pos++] = 6 ; cellsPtr [pos++] = 11 ; // Av-H-D
291312 ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
313+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
292314 cellsPtr [pos++] = 3 ; cellsPtr [pos++] = 3 ; cellsPtr [pos++] = 20 ; cellsPtr [pos++] = 15 ; // Av-B-G
293315 ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
316+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
294317 cellsPtr [pos++] = 3 ; cellsPtr [pos++] = 2 ; cellsPtr [pos++] = 7 ; cellsPtr [pos++] = 21 ; // Av-B-D
295318 ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
319+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
296320 cellsPtr [pos++] = 3 ; cellsPtr [pos++] = 19 ; cellsPtr [pos++] = 13 ; cellsPtr [pos++] = 9 ; // Ar-H-G
297321 ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
322+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
298323 cellsPtr [pos++] = 3 ; cellsPtr [pos++] = 8 ; cellsPtr [pos++] = 5 ; cellsPtr [pos++] = 18 ; // Ar-H-D
299324 ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
325+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
300326 cellsPtr [pos++] = 3 ; cellsPtr [pos++] = 12 ; cellsPtr [pos++] = 16 ; cellsPtr [pos++] = 0 ; // Ar-B-G
301327 ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
328+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
302329 cellsPtr [pos++] = 3 ; cellsPtr [pos++] = 17 ; cellsPtr [pos++] = 4 ; cellsPtr [pos++] = 7 ; // Ar-B-D
303330 ViewUpVectors->InsertNextTuple3 (0 ., 1 ., 0 .);
331+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
304332 cellArray->SetCells (6 + 12 + 8 , idsArray);
305333 CubePolyData->SetPolys (cellArray);
334+ ColorsVectors->InsertNextTuple3 (gray, gray, gray);
306335 idsArray->Delete ( ); idsArray = 0 ;
307336 cellArray->Delete ( ); cellArray = 0 ;
337+
308338// points->Delete ( ); points = 0;
309339 CubePolyDataMapper->SetInputData (CubePolyData);
310- CubePolyDataMapper->ScalarVisibilityOff ( );
340+ // CubePolyDataMapper->ScalarVisibilityOff ( );
341+ CubePolyDataMapper->ScalarVisibilityOn ( );
342+ CubePolyData->GetCellData ( )->SetScalars (ColorsVectors);
311343 CubeActor->SetMapper (CubePolyDataMapper);
312- CubeActor->GetProperty ( )->SetColor (.75 , .75 , .75 );
344+ // CubeActor->GetProperty ( )->SetColor (.75, .75, .75);
313345 CubeActor->PickableOn ( );
314346 AddPart (CubeActor);
315- HighlightPolyDataMapper->SetInputData (HighlightPolyData);
316- HighlightPolyDataMapper->ScalarVisibilityOff ( );
317- HighlightActor->SetMapper (HighlightPolyDataMapper);
318- HighlightActor->GetProperty ( )->SetColor (1 ., 0 ., 0 .);
319- HighlightActor->PickableOff ( );
320347
321348 XPlusVectorText = vtkSmartPointer<vtkVectorText>::New ( );
322349 XMinusVectorText = vtkSmartPointer<vtkVectorText>::New ( );
@@ -410,10 +437,10 @@ vtkViewCubeActor::vtkViewCubeActor ( )
410437
411438
412439vtkViewCubeActor::vtkViewCubeActor (const vtkViewCubeActor&)
413- : vtkPropAssembly ( ), Renderer (0 ), DrivenRenderer (0 ), CubePolyData ( ), HighlightPolyData ( ), CubeActor ( ), HighlightActor ( ), CubePolyDataMapper ( ), HighlightPolyDataMapper ( ),
440+ : vtkPropAssembly ( ), Renderer (0 ), DrivenRenderer (0 ), CubePolyData ( ), CubeActor ( ), CubePolyDataMapper ( ),
414441 CellPicker ( ), LastPickedFace ((unsigned char )-1), HighlightedFace ((unsigned char )-1),
415442 XPlusVectorText ( ), XMinusVectorText ( ), YPlusVectorText ( ), YMinusVectorText ( ), ZPlusVectorText ( ), ZMinusVectorText ( ),
416- XPlusActor ( ), XMinusActor ( ), YPlusActor ( ), YMinusActor ( ), ZPlusActor ( ), ZMinusActor ( ),
443+ XPlusActor ( ), XMinusActor ( ), YPlusActor ( ), YMinusActor ( ), ZPlusActor ( ), ZMinusActor ( ), ColorsVectors ( ), ViewUpVectors ( ),
417444 Transform (0 )
418445{
419446 assert (0 && " vtkViewCubeActor copy constructor is not allowed." );
@@ -504,13 +531,11 @@ void vtkViewCubeActor::SetTransform (vtkTransform* transform)
504531 while (0 != (property = collection->GetNextProp ( )))
505532 {
506533 vtkActor* actor = vtkActor::SafeDownCast (property);
507- if (( 0 != actor) && (actor != HighlightActor) )
534+ if (0 != actor)
508535 {
509536 actor->SetUserTransform (Transform);
510537 } // if (0 != actor)
511538 } // while (0 != (property = collection->GetNextProp ( )))
512- if (0 != HighlightActor)
513- HighlightActor->SetUserTransform (Transform);
514539} // vtkViewCubeActor::SetTransform
515540
516541
@@ -612,40 +637,25 @@ void vtkViewCubeActor::HighlightCallback (int x, int y)
612637 if ((0 == CellPicker.Get ( )) || (0 == Renderer) || (0 == DrivenRenderer))
613638 return ;
614639 assert (0 != CubePolyData.Get ( ));
615- assert (0 != HighlightPolyData.Get ( ));
616- assert (0 != HighlightActor.Get ( ));
617640
641+ CubePolyData->GetCellData ( )->SetActiveScalars (" Colors" );
618642 if (0 != CellPicker->Pick (x, y, 0 , Renderer))
619643 {
620644 if (HighlightedFace == CellPicker->GetCellId ( ))
621645 return ;
622-
646+
623647 if ((unsigned char )-1 != HighlightedFace)
624648 {
625- RemovePart (HighlightActor );
649+ ColorsVectors-> SetTuple3 (HighlightedFace, gray, gray, gray );
626650 } // if ((unsigned char)-1 != HighlightedFace)
627651 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 );
643653 } // if (0 != CellPicker->Pick (x, y, 0, Renderer))
644654 else
645655 {
646656 if ((unsigned char )-1 != HighlightedFace)
647657 {
648- RemovePart (HighlightActor );
658+ ColorsVectors-> SetTuple3 (HighlightedFace, gray, gray, gray );
649659 } // if ((unsigned char)-1 != HighlightedFace)
650660 HighlightedFace = (unsigned char )-1 ;
651661 } // else if (0 != CellPicker->Pick (x, y, 0, Renderer))
0 commit comments