[vtkusers] vtkPointWidget set the right position

ChenDawnWind cybfly1 at hotmail.com
Tue Apr 16 19:35:26 EDT 2013


Thanks for your advise.The codes below are the full function.Also the resources all in the attachments.
void vtkSimplePointExample(){	vtkSmartPointer<vtkRenderer> aRenderer =		vtkSmartPointer<vtkRenderer>::New();	vtkSmartPointer<vtkRenderWindow> renWin =		vtkSmartPointer<vtkRenderWindow>::New();	renWin->AddRenderer(aRenderer);
	vtkSmartPointer<vtkRenderWindowInteractor> iren =		vtkSmartPointer<vtkRenderWindowInteractor>::New();	iren->SetRenderWindow(renWin);
	vtkSmartPointer<vtkJPEGReader> jpegReader =		vtkSmartPointer<vtkJPEGReader>::New();  
	jpegReader->SetFilePrefix("C:/Users/DawnWind/Desktop/000/");	jpegReader->SetFilePattern("%s%d.jpg");	jpegReader->SetDataByteOrderToLittleEndian();	jpegReader->SetDataSpacing(2.0 / 3, 2.0 / 3, 1); 	jpegReader->SetFileNameSliceSpacing(1); 	jpegReader->SetDataExtent(0, 209, 0, 209, 0, 0);	jpegReader->Update();  
	vtkSmartPointer<vtkContourFilter> skinExtractor =		vtkSmartPointer<vtkContourFilter>::New();	skinExtractor->SetInputConnection(jpegReader->GetOutputPort());	skinExtractor->SetValue(0, 100);	#ifndef _OpenCV	// this codes get the points of the contour	// calculate the center and then show it with OpenCV	// The point center is the calculated center result.         // If you do not have OpenCV then just delete the codes in this ifndef_zone.	skinExtractor->Update();	vtkPolyData *data = skinExtractor->GetOutput();	vtkPoints *points = data->GetPoints();	vtkIdType pSize = points->GetNumberOfPoints();	vector<Point3d> pointsGroup;	Mat newMat = Mat::zeros(210, 210, CV_8UC1);	int matStep = newMat.step;	uchar *matData = newMat.data;	Point2d center;	for (int i = 0; i < pSize; i++)	{		double point[3];	    points->GetPoint(i, point);		Point3d p1;		p1.x = (point[0]);		p1.y = (point[1]);		p1.z = (point[2]);		*(matData + (int)point[0] + (int)point[1] * matStep) = 255;		pointsGroup.push_back(p1);		center.x += (int)point[0];		center.y += (int)point[1];	}	center.x /= pSize;	center.y /= pSize;	newMat.at<char>(center) = 255;	Mat dst0;	flip(newMat, dst0, 0);	imshow("dst0", dst0);	imshow("Mat", newMat);	waitKey();#endif
	vtkSmartPointer<vtkPolyDataMapper> skinMapper =		vtkSmartPointer<vtkPolyDataMapper>::New();	skinMapper->SetInputConnection(skinExtractor->GetOutputPort());	skinMapper->ScalarVisibilityOff();
	vtkSmartPointer<vtkActor> skin =		vtkSmartPointer<vtkActor>::New();	skin->SetMapper(skinMapper); 
	vtkSmartPointer<vtkOutlineFilter> outlineData =		vtkSmartPointer<vtkOutlineFilter>::New();	outlineData->SetInputConnection(jpegReader->GetOutputPort());
	vtkSmartPointer<vtkPolyDataMapper> mapOutline =		vtkSmartPointer<vtkPolyDataMapper>::New();	mapOutline->SetInputConnection(outlineData->GetOutputPort());
	vtkSmartPointer<vtkActor> outline =		vtkSmartPointer<vtkActor>::New();	outline->SetMapper(mapOutline);	outline->GetProperty()->SetColor(0, 0, 0);		vtkSmartPointer<vtkCamera> aCamera =		vtkSmartPointer<vtkCamera>::New();	aCamera->SetViewUp (0, 0, -1);	aCamera->SetPosition (0, 1, 0);	aCamera->SetFocalPoint (0, 0, 0);	aCamera->ComputeViewPlaneNormal();	aCamera->Azimuth(30.0);	aCamera->Elevation(30.0);
	aRenderer->AddActor(outline);	aRenderer->AddActor(skin);	aRenderer->SetActiveCamera(aCamera);	aRenderer->ResetCamera ();	aCamera->Dolly(1.5);
	aRenderer->SetBackground(.2, .3, .4);	renWin->SetSize(640, 480);
	aRenderer->ResetCameraClippingRange ();
#ifndef LINE	vtkSmartPointer<vtkLineSource> lineSource = vtkSmartPointer<vtkLineSource>::New();	//lineSource->SetPoint1(123, 90, 0);	lineSource->SetPoint1(center.x, center.y, 0);	lineSource->SetPoint2(center.x, center.y, 50);	//lineSource->SetPoint2(123, 90, 50);
	vtkSmartPointer<vtkSphereSource> sp = vtkSmartPointer<vtkSphereSource>::New();	//sp->SetCenter(center.x, center.y, 0);	sp->SetCenter(90, 117, 50);

	vtkSmartPointer<vtkDataSetMapper> lineMapper = vtkSmartPointer<vtkDataSetMapper>::New();	lineMapper->SetInput(lineSource->GetOutput());	vtkSmartPointer<vtkActor> lineActor = vtkSmartPointer<vtkActor>::New();	lineActor->SetMapper(lineMapper);	lineActor->GetProperty()->SetColor(1.0, 0, 0);	aRenderer->AddActor(lineActor);
	vtkSmartPointer<vtkPointWidget> pointWidget = vtkSmartPointer<vtkPointWidget>::New();	pointWidget->SetPosition(center.x, center.y, 0);	pointWidget->SetInteractor(iren);	pointWidget->On();#endif    renWin->Render();	renWin->SetWindowName("CYB");	iren->Initialize();	iren->Start();}
int main(){	vtkSimplePointExample();	return 0;}
Best wishes:)

DawnWind.ChenCSU

> Date: Tue, 16 Apr 2013 11:34:28 -0400
> Subject: Re: [vtkusers] vtkPointWidget set the right position
> From: daviddoria at gmail.com
> To: cybfly1 at hotmail.com
> CC: vtkusers at vtk.org
> 
> On Tue, Apr 16, 2013 at 10:01 AM, ChenDawnWind <cybfly1 at hotmail.com> wrote:
> > Hi everyone,I want to position a point in the model,then i use the codes
> > like this:
> >
> > vtkSmartPointer<vtkPointWidget> pointWidget =
> > vtkSmartPointer<vtkPointWidget>::New();
> > pointWidget->SetPosition(center.x, center.y, 0);
> > pointWidget->SetInteractor(iren);
> > pointWidget->On();
> >
> > But the point always appear at the corner of the outline of the model.
> > So i search the answer in the examples and google, and tried:
> >
> >         vtkSmartPointer<vtkPointWidget> pointWidget =
> > vtkSmartPointer<vtkPointWidget>::New();
> >         pointWidget->PlaceWidget();
> > pointWidget->SetPosition(center.x, center.y, 0);
> > pointWidget->SetInteractor(iren);
> > pointWidget->On();
> >
> > or some other codes but the problem still. So i wanna know what codes should
> > i use to achieve my goal?
> > Thanks!
> >
> > DawnWind.Chen
> > CSU
> 
> 
> Please send the most simple, fully compilable code you can that
> demonstrates the problem.
> 
> David
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130416/c1f308ef/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: result.jpg
Type: image/jpeg
Size: 68316 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130416/c1f308ef/attachment.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtkPointWidget.7z
Type: application/octet-stream
Size: 41444 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130416/c1f308ef/attachment.obj>


More information about the vtkusers mailing list