alex_xu
February 18, 2021, 2:22am
1
I try to read .pts file in the Paraview.
here is one point in the test.pts file. the content is as follows:
7.75 14.28 19.08
Based on the source code here
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPTSReader.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkPTSReader.h"
#include "vtkCellArray.h"
#include "vtkDataArray.h"
#include "vtkDoubleArray.h"
#include "vtkFloatArray.h"
This file has been truncated. show original
There should be one point read in the Paraview.
However, there is no point at all.
Furthermore, when I have two points in the test.pts, such as
7.75 14.28 19.08
7.75 14.28 20.08
I will have only 1 point (the 2nd point) in the Paraview.
What need I do to have all points in the .pts file?
Thanks!
aron.helser
(Aron Helser (Kitware))
February 18, 2021, 1:11pm
3
The comments in the source code you link make it a little more clear what is expected:
https://github.com/Kitware/VTK/blob/master/IO/Geometry/vtkPTSReader.cxx#L164
The first line of the .pts file should contain the number of points to be read.
alex_xu
February 18, 2021, 1:16pm
4
test1.pts (16 Bytes) test2.pts (18 Bytes)
Here are two test .pts files.
Each file has only one point.
test1.pts has point only.
test2.pts has the # of points at the first line.
alex_xu
February 18, 2021, 1:19pm
5
I tried both formats. You can find two test files in this thread.
Furthermore,
getline(file, buffer); // Scanf should match the integer part but not the string int numArgs = sscanf(buffer.c_str(), "%d%s", &tempNumPts, junk); if (numArgs == 1) { numPts = static_cast<vtkTypeInt32>(tempNumPts); break; } if (numArgs != -1) { // We have a file that doesn't have a number of points line // Instead we need to count the number of lines in the file // Remember we already read in the first line hence numPts starts // at 1 for (numPts = 1; getline(file, buffer); ++numPts) { if (numPts % 1000000 == 0) { this->UpdateProgress(0.1); if (this->GetAbortExecute()) {
It also shows that we can have points-only content.
aron.helser
(Aron Helser (Kitware))
February 18, 2021, 1:25pm
6
Cool - do you see any issue with the code?
alex_xu
February 18, 2021, 2:36pm
7
I just looked through the code.
The issue may be here:
if (this->CreateCells) { pids = new vtkIdType[targetNumPts]; } long lastCount = 0; for (long i = 0; i < numPts; i++) { // Should we process this point? Meaning that we skipped the appropriate number of points // based on the Max Number of points (onRatio) or the filtering by the read bounding box // OK to process based on Max Number of Points if (floor(i * onRatio) > lastCount) { lastCount++; sscanf(buffer.c_str(), "%lf %lf %lf %lf %lf %lf %lf", pt, pt + 1, pt + 2, irgb, irgb + 1, irgb + 2, irgb + 3); // OK to process based on bounding box if ((!this->LimitReadToBounds) || this->ReadBBox.ContainsPoint(pt)) { pid = newPts->InsertNextPoint(pt); // std::cerr << "Point " << i << " : " << pt[0] << " " << pt[1] << " " << pt[2] << "\n"; if (this->CreateCells)
let’s say onRatio = 1.0
when we process the first point,
lastCount = 0
i = 0
i * onRatio = 0
floor(i * onRatio) > lastCount is always false, lastCount remains 0
we miss the 1st point
however, in the following points
lastCount = 0
i = 1
i * onRatio = 1.0
floor(i * onRatio) > lastCount is true
we have the 2nd point,
lastCount becomes 1
then, i = 2, etc.
what’s more, even we set the Max Number of points
( onRatio = static_cast(this->MaxNumberOfPoints) / numPts;),
floor(i * onRatio) > lastCount doesn’t work as well IMHO.
I don’t understand why we need onRatio here,
why not use
if (this->MaxNumberOfPoints > lastCount)
But, I haven’t tested it yet. I am not very familiar with Paraview/VTK. And, my current work doesn’t allow me spend more time in debugging the vtkPTSReader. That’s the reason I posted this help-thread. Sorry about that.
alex_xu
February 25, 2021, 8:58pm
8
It seems that I forgot to @ you in the previous post, please take a look at my previous post.
thank you