[vtk-developers] Failed to go through the points in a poly data

weifeng0715 weifeng0715 at gmail.com
Mon May 30 11:59:53 EDT 2016


Hi, I have a piece of code intending to calculate the distance of between any
two points in a STL file, The code is listed below:

QString FilePth = ui->plainTextEdit_FilePath->toPlainText();
	if (FilePth.trimmed().isEmpty())
		return;
	QByteArray arrayByte = FilePth.toLocal8Bit();

	char * cDir_Condyle = (char *)malloc(1 + strlen(arrayByte.data()) +
strlen("/Condyle.stl"));
	strcpy(cDir_Condyle, arrayByte.data());
	strcat(cDir_Condyle, "/Condyle.stl");
	if (!(exists_test3(cDir_Condyle))) {
		ui->actionDistance->setEnabled(false);
		ui->statusbar->showMessage("No Condyle.");
		return;
	}
	//QString filename_out = QFileDialog::getSaveFileName(this, "Distance
list", FilePth+"\\distance histogram.txt", "Txt files (.txt);;Zip files
(.zip, *.7z)", 0, 0); // getting the filename (full path)
	QFile dataFile_Out(FilePth + "/distance histogram.txt");

	//Continue with model
	vtkSmartPointer<vtkSTLReader> stlReader_Condyle =
vtkSmartPointer<vtkSTLReader>::New();
	stlReader_Condyle->SetFileName(cDir_Condyle);
	stlReader_Condyle->Update();
	if (!dataFile_Out.open(QFile::WriteOnly | QFile::Truncate))
	{ 
		ui->statusbar->showMessage("Could not open the file.");
		return;
	}
		
	QTextStream stream(&dataFile_Out);
vtkSmartPointer<vtkPolyData> poly_Condyle =
vtkSmartPointer<vtkPolyData>::New();	
	poly_Condyle->ShallowCopy(stlReader_Condyle->GetOutput());

	vtkSmartPointer<vtkPoints> pts_Condyle = poly_Condyle->GetPoints();

	int numPts_Condyle = pts_Condyle->GetNumberOfPoints();
	
	
	for (int iCondyle_Start = 0; iCondyle_Start < numPts_Condyle - 1;
++iCondyle_Start)
	{
		double *coord_Condyle_Start = pts_Condyle->GetPoint(iCondyle_Start); //do
not delete variable allocated on the stack. You can call delete only on
memory you allocated dynamically (on the heap) using the new operator.

		
		for (int iCondyle_End = iCondyle_Start+1; iCondyle_End < numPts_Condyle;
++iCondyle_End)
		{ 
			double *coord_Condyle_End = pts_Condyle->GetPoint(iCondyle_End);
			double dist_tmp = vtkMath::Distance2BetweenPoints(coord_Condyle_Start,
coord_Condyle_End);			//sqrt(pow(coord_Condyle_Start[0] -
coord_Condyle_End[0], 2)
			//+pow(coord_Condyle_Start[1] - coord_Condyle_End[1], 2) +
pow(coord_Condyle_Start[2] - coord_Condyle_End[2], 2));
			stream	<< iCondyle_Start	<< "," << coord_Condyle_Start[0] << "," <<
coord_Condyle_Start[1] << "," << coord_Condyle_Start[2] << "," 
					<< iCondyle_End		<< ","<< coord_Condyle_End[0]	<< "," <<
coord_Condyle_End[1]	<< "," << coord_Condyle_End[2] << ","
				<< QString::number( dist_tmp) << "\n";
		}

	}

cout << "Done!" << endl;
	dataFile_Out.close();
*The problem is The coord_Condyle_Start is always equal to
coord_Condyle_End.*



--
View this message in context: http://vtk.1045678.n5.nabble.com/Failed-to-go-through-the-points-in-a-poly-data-tp5738520.html
Sent from the VTK - Dev mailing list archive at Nabble.com.


More information about the vtk-developers mailing list