#include <vtkActor.h>
#include <vtkProperty.h>
#include <vtkConeSource.h>
+#include <vtkAppendPolyData.h>
#include <vtkPolyDataMapper.h>
::VISU_CursorPyramid():
myHeight(10.0),
myRadius(5.0),
- myNbCones(6)
+ myNbCones(6),
+ myAppendFilter(vtkAppendPolyData::New()),
+ myMapper(vtkPolyDataMapper::New())
{
+ myAppendFilter->Delete();
+ myMapper->Delete();
+
+ myMapper->SetInput(myAppendFilter->GetOutput());
+
for(int i = 0; i < myNbCones; i++){
vtkConeSource* aConeSource = vtkConeSource::New();
+ myAppendFilter->AddInput(aConeSource->GetOutput());
aConeSource->SetResolution(4);
-
- vtkPolyDataMapper* aPolyDataMapper = vtkPolyDataMapper::New();
- aPolyDataMapper->SetInput(aConeSource->GetOutput());
- aConeSource->Delete();
-
- vtkActor* anActor = vtkActor::New();
- anActor->SetMapper(aPolyDataMapper);
- anActor->SetVisibility(0);
- anActor->SetPickable(0);
- aPolyDataMapper->Delete();
-
mySources[i] = aConeSource;
- myActors[i] = anActor;
- anActor->Delete();
- }
-
- myActors[1]->SetOrientation(0.0, 180.0, 0.0);
- myActors[3]->SetOrientation(0.0, 0.0, 180.0);
- myActors[5]->SetOrientation(180.0, 0.0, 0.0);
-
- for(int i = 0; i < 3; i++){
- myColor[i] = 1.0;
- myPos[i] = 0.0;
+ aConeSource->Delete();
}
}
//----------------------------------------------------------------------------
-int
-VISU_CursorPyramid
-::RenderOpaqueGeometry(vtkViewport *theViewport)
-{
- if(vtkRenderer* aRenderer = dynamic_cast<vtkRenderer*>(theViewport)){
- Render(aRenderer,GetMapper());
- return 1;
- }
- return 0;
-}
-
void
VISU_CursorPyramid
::Render(vtkRenderer *ren, vtkMapper *vtkNotUsed(m))
{
- this->EstimatedRenderTime = 0.0;
- for(int i = 0; i < myNbCones; i++){
- vtkActor* anActor = myActors[i].GetPointer();
- vtkMapper* aMapper = anActor->GetMapper();
-
- if(!aMapper)
- continue;
-
- vtkProperty* aProperty = anActor->GetProperty();
- aProperty->Render(this, ren);
-
- if(vtkProperty* aBackfaceProperty = anActor->GetBackfaceProperty()){
- aBackfaceProperty->Render(this, ren);
- anActor->SetBackfaceProperty(aBackfaceProperty);
- anActor->SetProperty(aProperty);
+ if (this->Mapper == NULL)
+ {
+ vtkErrorMacro("No mapper for actor.");
+ return;
}
- if(vtkTexture* aTexture = anActor->GetTexture())
- aTexture->Render(ren);
-
- anActor->Render(ren,aMapper);
- this->EstimatedRenderTime += aMapper->GetTimeToDraw();
- }
+ // render the property
+ if (!this->Property)
+ {
+ // force creation of a property
+ this->GetProperty();
+ }
+ this->Property->Render(this, ren);
+ if (this->BackfaceProperty)
+ {
+ this->BackfaceProperty->BackfaceRender(this, ren);
+ this->Device->SetBackfaceProperty(this->BackfaceProperty);
+ }
+ this->Device->SetProperty(this->Property);
+
+ // render the texture
+ if (this->Texture)
+ {
+ this->Texture->Render(ren);
+ }
+
+ // make sure the device has the same matrix
+ vtkMatrix4x4 *matrix = this->Device->GetUserMatrix();
+ this->GetMatrix(matrix);
+
+ this->Device->Render(ren,Mapper);
+ this->EstimatedRenderTime = Mapper->GetTimeToDraw();
}
VISU_CursorPyramid
::SetHeight(float theHeight)
{
- Init(theHeight, myRadius, myPos, myColor);
+ Init(theHeight, myRadius, GetPosition(), GetProperty()->GetColor());
}
//----------------------------------------------------------------------------
float thePos[3],
float theColor[3])
{
- int i;
- myHeight=theHeight;
- myRadius=theRadius;
- for (i=0; i<3; ++i){
- myPos[i]=thePos[i];
- myColor[i]=theColor[i];
- }
- for(i = 0; i < myNbCones; ++i){
+ SetPosition(thePos[0],thePos[1],thePos[2]);
+ GetProperty()->SetColor(theColor);
+ SetMapper(myMapper.GetPointer());
+
+ myHeight = theHeight;
+ myRadius = theRadius;
+
+ for(int i = 0; i < myNbCones; ++i){
vtkConeSource* aSource = mySources[i].GetPointer();
aSource->SetHeight(theHeight);
// Set the angle of the cone. As a side effect, the angle plus height sets
// the base radius of the cone.
aSource->SetAngle(20.0);
-
- vtkActor* anActor = myActors[i].GetPointer();
- anActor->SetPosition(thePos[0],thePos[1],thePos[2]);
- anActor->GetProperty()->SetColor(theColor);
}
- float aD = -0.5*theHeight - theRadius;
+ float aDisplacement = -0.5*theHeight - theRadius;
// X
- mySources[0]->SetCenter(aD, 0.,0.);
- mySources[1]->SetCenter(aD, 0.,0.);
+ mySources[0]->SetDirection(1.0, 0.0, 0.0);
+ mySources[0]->SetCenter(aDisplacement, 0.0, 0.0);
+
+ // It is impossible to inverse direction around X axis (VTK bug)
+ mySources[1]->SetDirection(-VTK_LARGE_FLOAT, 1.0, 0.0); // A workaround
+ mySources[1]->SetCenter(-aDisplacement, 0.0, 0.0);
// Y
- mySources[2]->SetDirection(0., 1., 0.);
- mySources[2]->SetCenter(0, aD, 0.);
+ mySources[2]->SetDirection(0.0, 1.0, 0.0);
+ mySources[2]->SetCenter(0.0, aDisplacement, 0.0);
- mySources[3]->SetDirection(0., 1., 0.);
- mySources[3]->SetCenter(0., aD, 0.);
+ mySources[3]->SetDirection(0.0, -1.0, 0.0);
+ mySources[3]->SetCenter(0.0, -aDisplacement, 0.0);
// Z
- mySources[4]->SetDirection(0., 0., 1.);
- mySources[4]->SetCenter(0, 0., aD);
+ mySources[4]->SetDirection(0.0, 0.0, 1.0);
+ mySources[4]->SetCenter(0.0, 0.0, aDisplacement);
- mySources[5]->SetDirection(0., 0., 1.);
- mySources[5]->SetCenter(0., 0., aD);
+ mySources[5]->SetDirection(0.0, 0.0, -1.0);
+ mySources[5]->SetCenter(0.0, 0.0, -aDisplacement);
}