<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Hi,<br><br>vtkActor2D is not able to do this apparently from itself. Therefore, I have written<br>my own callback-function which simply questions on the mousewheel movement and plots<br>the 2D actor in the desired size anew. <br>I still have the problem with the adaptation of the window size. To find out whether I<br>chaneges the windowframe, I will question permanently on the cursor position. If there<br>is better solution for it (e.g. finished functions), let it me know please.<br><br>.luxtheme.<br><br>my new code: <br><br>//Now you can zoom in or out with your mousewheel<br>#include "vtkRenderWindow.h"<br>#include "vtkRenderWindowInteractor.h"<br>#include "vtkRenderer.h"<br>#include "vtkPolyDataMapper2D.h"<br>#include "vtkCellArray.h"<br>#include "vtkPoints.h"<br>#include "vtkPolyData.h"<br>#include "vtkActor2D.h"<br>#include "vtkProperty2D.h"<br>#include
"vtkCommand.h"<br><br>#include <cstdlib><br>#include <ctime><br><br>//random signal<br>class randomSignal<br>{<br>public:<br> int event_array_time[100];<br> int event_array_bit[100];<br> int timeLine; <br> int array_index;<br><br> randomSignal(): event_array_time(), event_array_bit(), timeLine(2000), array_index(0) { }<br><br> void generate()<br> {<br> srand((unsigned)time(0));<br> int time = 0;<br> int start_bit = 0;<br><br> while(time<timeLine)<br> {<br> array_index++;<br>
event_array_time[array_index-1]=time;<br> event_array_bit[array_index-1]=start_bit;<br> int random_event = (rand()%500)+1;<br> time+=random_event;<br><br> start_bit=(start_bit+1)%2;<br> }<br> event_array_time[array_index-1]=timeLine;<br> }<br><br>};<br><br>void drawSignal(randomSignal *random, vtkActor2D *actor, int Xaxis)<br>{<br> int *event_array_time = random->event_array_time;<br> int *event_array_bit = random->event_array_bit;<br> int timeLine = random->timeLine; <br> int array_index = random->array_index;<br><br> vtkPoints *points =
vtkPoints::New();<br> vtkCellArray *lines = vtkCellArray::New();<br> int pID = 0;<br><br> vtkPolyData* polyData = vtkPolyData::New();<br> vtkPolyDataMapper2D *mapper = vtkPolyDataMapper2D::New();<br><br> //plot signal<br> points->InsertNextPoint((double)Xaxis/timeLine*event_array_time[0],300*event_array_bit[0],0); <br> points->InsertNextPoint((double)Xaxis/timeLine*event_array_time[1],300*event_array_bit[0],0); <br><br> lines->InsertNextCell(2); <br> lines->InsertCellPoint(pID); <br> lines->InsertCellPoint(pID+1); <br>
pID+=2;<br><br> for (int i=1; i<array_index-1; i++) {<br><br> // toggle line<br> points->InsertNextPoint((double)Xaxis/timeLine*event_array_time[i],300*event_array_bit[i],0); <br> points->InsertNextPoint((double)Xaxis/timeLine*event_array_time[i],300*event_array_bit[i+1],0); <br><br> lines->InsertNextCell(2); <br> lines->InsertCellPoint(pID); <br> lines->InsertCellPoint(pID+1); <br> pID+=2;<br><br> // High-/ Low-line<br>
points->InsertNextPoint((double)Xaxis/timeLine*event_array_time[i],300*event_array_bit[i],0); <br> points->InsertNextPoint((double)Xaxis/timeLine*event_array_time[i+1],300*event_array_bit[i],0); <br><br> lines->InsertNextCell(2); <br> lines->InsertCellPoint(pID); <br> lines->InsertCellPoint(pID+1); <br> pID+=2;<br> }<br><br> // Create actor<br> polyData->SetPoints(points); <br> polyData->SetLines(lines);
<br> mapper->SetInput(polyData); <br> actor->SetMapper(mapper);<br> actor->GetProperty()->SetColor(0,1,1); <br>}<br><br>//mouse moved<br>class callbackZoom: public vtkCommand<br>{<br>public:<br> static callbackZoom *New()<br> { return new callbackZoom; }<br> virtual void Execute(vtkObject *caller, unsigned long eventId, void*)<br> {<br> if(eventId == MouseWheelBackwardEvent) {<br> Xaxis=(int)(Xaxis*0.9);<br> drawSignal(random, actor, Xaxis);<br> renWin->Render();<br>
} <br> else if(eventId == MouseWheelForwardEvent) {<br> Xaxis=(int)(Xaxis*1.1);<br> drawSignal(random, actor, Xaxis);<br> renWin->Render();<br> } <br> }<br> <br> callbackZoom() : actor(), Xaxis(tempX), renWin(), random() {}<br> vtkRenderWindow *renWin;<br> randomSignal *random;<br> int tempX;<br> int& Xaxis;<br> vtkActor2D *actor;<br>};<br><br>//MAIN<br>void main()<br>{<br> int Xaxis = 800;<br><br> // generate random signal<br> randomSignal *random = new randomSignal();<br> random->generate();
<br> cout << "\n\nAI: " << random->array_index << endl;<br> <br> vtkActor2D *actor = vtkActor2D::New();<br> drawSignal(random, actor, Xaxis);<br><br> // Create a renderer<br> vtkRenderer* ren = vtkRenderer::New();<br> ren->SetBackground(0.75,0.25,0.25);<br> ren->AddActor(actor);<br><br> // Create a render window<br> vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();<br> vtkRenderWindow* renWin = vtkRenderWindow::New();<br> renWin->AddRenderer(ren);<br> renWin->SetSize( 800,300 );<br> renWin->SetInteractor( iren
);<br><br> // Event<br> callbackZoom *cbZoom = callbackZoom::New();<br> cbZoom->actor = actor;<br> cbZoom->Xaxis = Xaxis;<br> cbZoom->renWin = renWin;<br> cbZoom->random = random;<br> iren->AddObserver(vtkCommand::MouseWheelBackwardEvent,cbZoom);<br> iren->AddObserver(vtkCommand::MouseWheelForwardEvent,cbZoom);<br><br> iren->Initialize();<br> renWin->Render();<br> iren->Start();<br><br> //...<br>}<br><br>--- Öner F <i><luxtheme@yahoo.de></i> schrieb am <b>Di, 26.5.2009:<br></b><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><b><br>Von: luxtheme <luxtheme@yahoo.de><br>Betreff: [vtkusers] Is it possible to change size of a vtkActor2D?<br>An:
vtkusers@vtk.org<br>Datum: Dienstag, 26. Mai 2009, 11:35<br><br></b><div id="yiv1137704513"><style type="text/css"><!--#yiv1137704513 DIV {margin:0px;}--></style><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><div style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: arial,helvetica,sans-serif;"><b>Hi,</b></span><b><br style="font-family: arial,helvetica,sans-serif;"><br style="font-family: arial,helvetica,sans-serif;"><span style="font-family: arial,helvetica,sans-serif;">I want to display analog & digital signals in a cartesian coordinate system which </span><br style="font-family: arial,helvetica,sans-serif;"><span style="font-family: arial,helvetica,sans-serif;">should be zoomable. I have tried several approaches and simply do not get further.</span><br style="font-family: arial,helvetica,sans-serif;"><span style="font-family: arial,helvetica,sans-serif;">So I need
help.</span><br style="font-family: arial,helvetica,sans-serif;"><br style="font-family: arial,helvetica,sans-serif;"><span style="font-family: arial,helvetica,sans-serif;">One of the approaches which I try is vtkActor2D. Problem is, that if I change the</span><br style="font-family: arial,helvetica,sans-serif;"><span style="font-family: arial,helvetica,sans-serif;">window size, it does not change the size of the 2D actor. First position of the</span><br style="font-family: arial,helvetica,sans-serif;"><span style="font-family: arial,helvetica,sans-serif;">2D actor I can wonderfully set up, but position2 cannot be changed. Height and</span><br style="font-family: arial,helvetica,sans-serif;"><span style="font-family: arial,helvetica,sans-serif;">width of the 2D actor remains always constant.</span><br style="font-family: arial,helvetica,sans-serif;"><span style="font-family: arial,helvetica,sans-serif;">Is it possible to zoom with vtkActor2D? If so,
how?</span><br style="font-family: arial,helvetica,sans-serif;"><span style="font-family: arial,helvetica,sans-serif;">Which additional functions do I need?</span><br style="font-family: arial,helvetica,sans-serif;"><br style="font-family: arial,helvetica,sans-serif;"><span style="font-family: arial,helvetica,sans-serif;">.luxtheme.</span><br></b></div></div></div><br></blockquote></td></tr></table><br>