[vtkusers] Drawing a simple line graph (CONTINUES...)
Isidro Moreno
morenoisidro at yahoo.com.ar
Sat Jun 30 09:46:21 EDT 2007
Hi, I have been dealing with vtkActor2D problem for the last 3 week and got no solutions. I found somebody in vtkusers archive who had the same problem. For those who don know excactly what I'm talking about, please visit:
http://public.kitware.com/pipermail/vtkusers/2006-November/088196.html
It's unbelievable that a simple line or polygon can't be drawn in the plane properly. I think somebody must have the answer to my question. Now, supposing you must have seen Beth's code while following the subject in the link above, I'll show you my own code (and the answers from those who have tried give me some help):
vtkLineSource *linea=vtkLineSource::New();
vtkPolyDataMapper2D *mapper=vtkPolyDataMapper2D::New();
vtkActor2D *actor=vtkActor2D::New();
vtkRenderer *render=vtkRenderer::New();
vtkRenderWindow *ventana=vtkRenderWindow::New();
vtkRenderWindowInteractor *interac=vtkRenderWindowInteractor::New();
vtkCoordinate *coor=vtkCoordinate::New();
int *dim_ven=new int [2];
dim_ven[0]=600;
dim_ven[1]=400;
int segmentos;
cout<<"Ingrese cantidad de segmentos: ";
cin>>segmentos;
cout<<endl;
linea->SetResolution(segmentos);
linea->Update();
double PI=3.1416;
double delta=2*PI/(dim_ven[0]*1.0);
double resolucion=(dim_ven[0]*1.0)/(segmentos*1.0);
for(int i=0;i<linea->GetOutput()->GetPoints()->GetNumberOfPoints();i++){
linea->
GetOutput()->
GetPoints()->
SetPoint(i,
i*resolucion,
(dim_ven[1]/2)*sin(i*resolucion*delta)+(dim_ven[1]/2),
0.0);}
mapper->SetInput(linea->GetOutput());
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(1.0,0.0,0.0);
render->AddActor2D(actor);
render->SetBackground(0.1,0.2,0.4);
ventana->AddRenderer(render);
interac->SetRenderWindow(ventana);
ventana->Render();
interac->Start();
linea->Delete();
mapper->Delete();
actor->Delete();
render->Delete();
ventana->Delete();
interac->Delete();
coor->Delete();
delete [] dim_ven;
Thanks for your time/help!!
These are the responses ordered from the newest to the oldest:
> OK, let's see; as you must have seen the code below, it consist of drawing
> a diagonal line. Width a Height are the dimensions the rectangle in which
> this line is defined in. Using these two methods is the same as doing
> vtkActor2D->GetPosition2Coordinate->SetValue(x,y) (where x=width &
> y=height - see HTML help of vtkActor2D) as I've explained below. The
> pourpose of all these is to autoscale any figure in the plane when the
> window's size changes (not just a line but also a polygon, rectangle,
> etc). In fact, I've used this code to draw a period of the sinus function
> and it was fine! But I can't make it fit my window. It put a simple line
> in the code below to make the things easier to understand, but you're the
> second who asks me the same question. Should I be more clear and put the
> actual code? Sorry for my english, I'm spanish speaker.
> I know I can do this with actor 3D, but I think It's not good using it
> in terms of design since I'm working in the plane and many unused memory
> would be kept in if I use actor3D.
>
>
>> Isidro,
>>
>> Could you be a bit more clear about what you want to do exactly?
>> Does not a line have zero 'width' and 'height' by definition?
>> If you want to change the size of your line, perhaps you could change
>> Point1
>> and Point2 on your line when you needed. Otherwise you could also
>> position
>> your line in 3D instead of using an Actor2D, this would give you some
>> more
>> flexibility.
>>
>> -SN
>>
>> -----Original Message-----
>>
>> I've been trying so hard, and It seems vtkActor2D ignores SetPositon2()
>> method (or vtkActor2D->GetPosition2Coordinate->SetValue(x,y) method - see
>> HTML vtkActor2D help). Could somebody help me if this is what's actually
>> happening?
>>
>>
>>>> On 6/26/07, Isidro Moreno <morenoisidro at yahoo.com.ar> wrote:
>>>>> Mark,
>>>>>
>>>>> SetWidth() and SetHeight() methods (vtkProp's methods),define the
>>>>> dimensions of the rectangle in which the line is drawn (it could be
>>>>> not
>>>>> a
>>>>> line, but also a circle, a polygon, etc.). In fact, that rectangle is
>>>>> which
>>>>> I want to autoscale when window's size changes. As a result, the line
>>>>> would
>>>>> fit to it. That's what I've understood till now. But I could be
>>>>> wrong...
>>>>>
>>>>> Isidro
>>>>>
>>>>>
>>>>> >
>>>>> > On 6/26/07, Isidro Moreno <morenoisidro at yahoo.com.ar> wrote:
>>>>> >>
>>>>> >>
>>>>> >> Hello! I've made a simple VTK/C++ test program. It's just a 2D
>>>>> >> line.
>>>>> >> Now,
>>>>> >> I
>>>>> >> don't know how to make the line size change. I've tried many
>>>>> >> methods;
>>>>> >> and
>>>>> >> changing vtkActor's coordinate system (vtkActor2D's), but no
>>>>> >> results.
>>>>> >> I
>>>>> >> even
>>>>> >> wonder what coordinate system is vtkLineSource defined in (see code
>>>>> >> below).
>>>>> >>
>>>>> >> Here's my code:
>>>>> >>
>>>>> >> vtkLineSource *line=vtkLineSource::New();
>>>>> >> line->SetPoint1(20.0,20.0,0.0); // what Coordinate System??
>>>>> >> line->SetPoint2(80.0,150.0,0.0); // what Coordinate System??
>>>>> >>
>>>>> >> vtkPolyDataMapper2D *mapper=vtkPolyDataMapper2D::New();
>>>>> >> mapper->SetInput(line->GetOutput());
>>>>> >>
>>>>> >> vtkActor2D *actor=vtkActor2D::New();
>>>>> >> actor->SetMapper(mapper);
>>>>> >> actor->GetProperty()->SetColor(1.0,0.0,0.0);
>>>>> >> actor->SetWidth(0.5); // Doesn't work!! - The same happens
>>>>> >> with vtkActor2D->GetPosition2Coordinate->SetValue(double width ,
>>>>> >> double height)
>>>>> >> actor->SetHeight(0.5); // Doesn't work!! - The same happens
>>>>> >> with vtkActor2D->GetPosition2Coordinate->SetValue(double width ,
>>>>> >> double height)
>>>>> >>
>>>>> >> vtkRenderer *render=vtkRenderer::New();
>>>>> >> vtkRenderWindow *win=vtkRenderWindow::New();
>>>>> >> win->AddRenderer(render);
>>>>> >>
>>>>> >> vtkRenderWindowInteractor
>>>>> >> *interac=vtkRenderWindowInteractor::New();
>>>>> >> interac->SetRenderWindow(win);
>>>>> >>
>>>>> >> render->AddActor2D(actor);
>>>>> >> render->SetBackground(0.1,0.2,0.4);
>>>>> >>
>>>>> >> win->Render();
>>>>> >>
>>>>> >> interac->Initialize();
>>>>> >> interac->Start();
>>>>> >>
>>>>> >> line->Delete();
>>>>> >> mapper->Delete();
>>>>> >> actor->Delete();
>>>>> >> render->Delete();
>>>>> >> win->Delete();
>>>>> >> interac->Delete();
>>>>> >>
>>>>> >> I want to make the line resize when changing windows size. I'd be
>>>>> >> very
>>>>> >> grateful if somebody could help me with this. Thanks!!!
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070630/372aaf95/attachment.htm>
More information about the vtkusers
mailing list