c++ - Apply transformation to PolyData -
i want able apply tranformations polydata no matter how try it, doesn't work.
here have "drawing" polydata in class call drawing.cpp:
drawing.h
vtksmartpointer<vtkplane> clipplane; vtksmartpointer<vtkimplicitplanerepresentation> planerep; vtksmartpointer<vtkactor> actorplanesource; vtksmartpointer<vtkactor> mainactor; vtksmartpointer<vtktransformpolydatafilter> transformfilter; vtksmartpointer<vtktransform> translation ; vtkcontextview* ctxview ; vtkrenderwindow* win ; vtkrenderer* ren ; vtkcamera* cam ; vtksmartpointer<vtkpolydata> inputpolydata;
then read function called , starts rendering, here function in drawing.cpp:
void drawing::read(){ std::string filename = bunny; // read data file vtksmartpointer<vtkxmlpolydatareader> reader =vtksmartpointer<vtkxmlpolydatareader>::new(); reader->setfilename(filename.c_str()); reader->update(); inputpolydata = reader->getoutput(); cout << "file found , loaded : " << filename << endl ; vtksmartpointer<vtktransform> translation = vtksmartpointer<vtktransform>::new(); translation->translate(0.3, -0.05, 0); transformfilter = vtksmartpointer<vtktransformpolydatafilter>::new(); //transformfilter->setinputconnection(reader->getoutputport()); transformfilter->setinputdata(inputpolydata); transformfilter->settransform(translation); //transformfilter->update(); vtksmartpointer<vtkpolydatamapper> mapper = vtksmartpointer<vtkpolydatamapper>::new(); mapper->setinputconnection(transformfilter->getoutputport()); mainactor = vtksmartpointer<vtkactor>::new(); mainactor->setmapper(mapper); ren->addactor(mainactor); vtkrenderwindowinteractor *iren = vtkrenderwindowinteractor::new(); iren->setrenderwindow(win); vtkinteractorstylemultitouchcamera *style = vtkinteractorstylemultitouchcamera::new(); iren->setinteractorstyle(style); //start event loop iren->initialize(); iren->start(); defineclipping(); win->polygonsmoothingon(); win->render(); win->start(); }
from this, have other thread running server gets messages , has pointer drawing object , supposed call 1 of these 3 functions depending on message gets clients:
void drawing::scale(float k){ vtksmartpointer<vtktransform> transform =vtksmartpointer<vtktransform>::new(); transform->scale(5,1,1); vtksmartpointer<vtktransformfilter> transformfilter = vtksmartpointer<vtktransformfilter>::new(); transformfilter->setinputconnection(cone->getoutputport()); transformfilter->settransform(transform); mapper->setinputconnection(transformfilter->getoutputport()); ren->getactivecamera(); } void drawing::translate(float x, float y, float z){ cout << "translate: " << x << " - " << " - " << y << " - " << z << endl ; vtksmartpointer<vtktransform> transform1a = vtksmartpointer<vtktransform>::new(); //transform1a->translate(x,y,z); //transformfilter->settransform(transform1a); //transformfilter->update(); double* position = mainactor->getposition(); mainactor->setposition(position[0]+x,position[1]+y,position[2]+z); } void drawing::rotate(float x, float y, float z){ cout << "rotate: " << x << " - " << " - " << y << " - " << z << endl ; vtksmartpointer<vtktransform> transform1a = vtksmartpointer<vtktransform>::new(); //transform1a->postmultiply(); //transform1a->rotatex(x); //transform1a->rotatey(y); //transform1a->rotatez(z); //mainactor->setusertransform(transform1a); mainactor->rotatewxyz(20,1,0,0); }
none of these functions work because nothing changing in rendering windows unless click in rendering window itself. thought maybe should try , add every transformation functions: ctxview->render();
when get:
error ressource busy.
i'm newbie in vtk find weird can't simple transformation object. that.
edit: ok after hours of trying different things have notices if comment out line iren->start();
rotations , translations called. however, program closes there done , cannot interact window anymore. have insights on that?
thanks in advance.
yes, try give little code made rotations polydata, guess different pipeline (i using vtkimagereslice object m_preslice):
int nextent[3]; double dspacing[3]; double dorigin[3]; m_preader->getoutput()->getspacing(dspacing); m_preader->getoutput()->getorigin(dorigin); m_preader->getoutput()->getdimensions(nextent); double dcenter[3]; dcenter[0] = dorigin[0] + dspacing[0] * 0.5 * nextent[0]; // nextent[0] width dcenter[1] = dorigin[1] + dspacing[1] * 0.5 * nextent[1]; // nextent[1] height dcenter[2] = dorigin[2] + dspacing[2] * 0.5 * nextent[2]; // nextent[2] depth vtksmartpointer<vtktransform> ptransform = vtksmartpointer<vtktransform>::new(); ptransform->premultiply(); int ndirection = cdirectiondlg::getdirection(); if(cdirectiondlg::dir_axial == ndirection) { ptransform->translate(dcenter[0], 0, dcenter[2]); ptransform->rotatey(180); ptransform->translate(-dcenter[0], 0, -dcenter[2]); } else { ptransform->translate(dcenter[0], dcenter[1], 0); ptransform->rotatez(180); ptransform->translate(-dcenter[0], -dcenter[1], 0); } m_preslice->setreslicetransform(ptransform); m_preslice->setinterpolationmodetolinear(); m_preslice->update();
consider way rotate object in view moving camera ... hope you.
Comments
Post a Comment