[vtkusers] Arrow Problem
ankitramani
ankitvtk at googlemail.com
Sat Mar 17 08:09:51 EDT 2012
I am using this code for displaying arrow on screen not arrow source. then i
combine arrows, cylinder and line in assembly.
******************************************************
vtkPolyData *pd1 = vtkPolyData::New();
vtkCellArray *ca1 = vtkCellArray::New();
vtkPoints *pts1 = vtkPoints::New();
pts1->InsertNextPoint(0, 1, 0);
pts1->InsertNextPoint(8, 1, 0);
pts1->InsertNextPoint(8, 2, 0);
pts1->InsertNextPoint(10, 0, 0);
pts1->InsertNextPoint(8, -2, 0);
pts1->InsertNextPoint(8, -1, 0);
pts1->InsertNextPoint(0, -1, 0);
ca1->InsertNextCell(7);
ca1->InsertCellPoint(0);
ca1->InsertCellPoint(1);
ca1->InsertCellPoint(2);
ca1->InsertCellPoint(3);
ca1->InsertCellPoint(4);
ca1->InsertCellPoint(5);
ca1->InsertCellPoint(6);
pd1->SetPoints(pts1);
pd1->SetPolys(ca1);
/*vtkPolyData *pd21 = vtkPolyData::New();
vtkCellArray *ca21 = vtkCellArray::New();
vtkPoints *pts21 = vtkPoints::New();
pts21->InsertNextPoint(0, 1, 0);
pts21->InsertNextPoint(8, 1, 0);
pts21->InsertNextPoint(8, 2, 0);
pts21->InsertNextPoint(10, 0.01, 0);
ca21->InsertNextCell(4);
ca21->InsertCellPoint(0);
ca21->InsertCellPoint(1);
ca21->InsertCellPoint(2);
ca21->InsertCellPoint(3);
pd21->SetPoints(pts21);
pd21->SetLines(ca21);*/
vtkImplicitModeller *arrowIM1 = vtkImplicitModeller::New();
arrowIM1->SetInput(pd1);
arrowIM1->SetSampleDimensions(50, 20, 8);
vtkContourFilter *arrowCF1 = vtkContourFilter::New();
arrowCF1->SetInput((vtkDataObject*)arrowIM1->GetOutput());
arrowCF1->SetValue(0, 0.2);
vtkWarpTo *arrowWT1 = vtkWarpTo::New();
arrowWT1->SetInput(arrowCF1->GetOutput());
arrowWT1->SetPosition(5, 0, 5);
arrowWT1->SetScaleFactor(0.85);
arrowWT1->AbsoluteOn();
vtkTransform *arrowT1 = vtkTransform::New();
arrowT1->RotateY(60);
arrowT1->Translate(-1.33198, 0, -1.479);
arrowT1->Scale(5, 5, 5);
vtkTransformFilter *arrowTF1 = vtkTransformFilter::New();
arrowTF1->SetInput(arrowWT1->GetOutput());
arrowTF1->SetTransform(arrowT1);
vtkDataSetMapper *arrowMapper1 = vtkDataSetMapper::New();
arrowMapper1->SetInput(arrowTF1->GetOutput());
arrowMapper1->ScalarVisibilityOff();
// draw the azimuth arrows
vtkLODActor *a1Actor1 = vtkLODActor::New();
a1Actor1->SetMapper(arrowMapper1);
a1Actor1->SetPosition(400, 300, 50);
a1Actor1->RotateZ(90);
a1Actor1->GetProperty()->SetColor(0.3,1, 0.3);
a1Actor1->GetProperty()->SetSpecularColor(1,1, 1);
a1Actor1->GetProperty()->SetSpecular(0.3);
a1Actor1->GetProperty()->SetSpecularPower(20);
a1Actor1->GetProperty()->SetAmbient(0.2);
a1Actor1->GetProperty()->SetDiffuse(0.8);
vtkLODActor *a2Actor1 = vtkLODActor::New();
a2Actor1->SetMapper(arrowMapper1);
a2Actor1->RotateX(180);
a2Actor1->RotateZ(-90);
a2Actor1->SetPosition(400, 300, 50);
a2Actor1->GetProperty()->SetColor(0.3,1, 0.3);
a2Actor1->GetProperty()->SetSpecularColor(1,1, 1);
a2Actor1->GetProperty()->SetSpecular(0.3);
a2Actor1->GetProperty()->SetSpecularPower(20);
a2Actor1->GetProperty()->SetAmbient(0.2);
a2Actor1->GetProperty()->SetDiffuse(0.8);
*****************************************************************
this code for picking the arrow and when i click on arrow, it translate in
xyz axis.
**************************************************************
if (event == vtkCommand::LeftButtonPressEvent)
{
int currPos[3];
interactor->GetEventPosition(currPos);
vtkPropPicker *picker=vtkPropPicker::New();
interactor->SetPicker(picker);
picker->Pick(currPos[0], currPos[1], currPos[2], this->renderer3D);
vtkSmartPointer<vtkPropCollection> collection1 =
vtkSmartPointer<vtkPropCollection>::New();
collection1 =
interactor->GetPicker()->GetRenderer()->GetPickResultProps();
if(collection1)
{
collection1->InitTraversal();
for (int i = 1; i < collection1->GetNumberOfItems(); i++)
{
vtkActor *actor =vtkActor::SafeDownCast(collection1->GetNextProp());
if(actor == tempArr51Actor)
{
double *pos = tempImpAssembly->GetPosition();
tempImpAssembly->SetPosition(pos[0]-10,pos[1],pos[2]);
}
***********************************
assembly should translate when i click on arrow(any area of arrow)
but it should only work, when i click on end part(tail) of arrow.
i know, i miss some stupid thing in my code.
help me.
thnx in advance..
--
View this message in context: http://vtk.1045678.n5.nabble.com/Arrow-Problem-tp5573517p5573517.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list