Skip to content

Commit

Permalink
ENH: ReadCSVFilter and TriangleCentroidFilter improvements (#852)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson authored Feb 9, 2024
1 parent 3a1e77e commit be6c1b9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace
class CalculateCentroidsImpl
{
public:
CalculateCentroidsImpl(const TriangleGeom* triangleGeom, Float32Array* centroids, const std::atomic_bool& shouldCancel)
CalculateCentroidsImpl(const TriangleGeom* triangleGeom, Float64Array* centroids, const std::atomic_bool& shouldCancel)
: m_TriangleGeom(triangleGeom)
, m_Centroids(centroids)
, m_ShouldCancel(shouldCancel)
Expand Down Expand Up @@ -52,7 +52,7 @@ class CalculateCentroidsImpl

private:
const TriangleGeom* m_TriangleGeom = nullptr;
Float32Array* m_Centroids = nullptr;
Float64Array* m_Centroids = nullptr;
const std::atomic_bool& m_ShouldCancel;
};
} // namespace
Expand Down Expand Up @@ -83,7 +83,7 @@ Result<> TriangleCentroid::operator()()
const AttributeMatrix& faceAttributeMatrix = triangleGeom->getFaceAttributeMatrixRef();

const DataPath pCentroidsPath = m_InputValues->TriangleGeometryDataPath.createChildPath(faceAttributeMatrix.getName()).createChildPath(m_InputValues->CentroidsArrayName);
auto* centroidsArray = m_DataStructure.getDataAs<Float32Array>(pCentroidsPath);
auto* centroidsArray = m_DataStructure.getDataAs<Float64Array>(pCentroidsPath);

// Parallel algorithm to calculate the centroids
ParallelDataAlgorithm dataAlg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,17 +429,26 @@ IFilter::PreflightResult ReadCSVFileFilter::preflightImpl(const DataStructure& d

s_HeaderCache[s_InstanceId].FilePath = readCSVData.inputFilePath;

usize lineCount = 0;
while(!in.eof())
// usize lineCount = 0;
usize lineCount = std::count_if(std::istreambuf_iterator<char>{in}, {}, [](char c) { return c == '\n'; });

if(headerMode == ReadCSVData::HeaderMode::LINE)
{
std::string line;
std::getline(in, line);
lineCount++;

if(headerMode == ReadCSVData::HeaderMode::LINE && lineCount == readCSVData.headersLine)
in.seekg(0); // Rewind back to the beginning.
usize currentLine = 0;
while(!in.eof())
{
s_HeaderCache[s_InstanceId].Headers = line;
s_HeaderCache[s_InstanceId].HeadersLine = readCSVData.headersLine;
std::string line;
std::getline(in, line);
currentLine++;

if(currentLine == readCSVData.headersLine)
{
s_HeaderCache[s_InstanceId].Headers = line;
s_HeaderCache[s_InstanceId].HeadersLine = readCSVData.headersLine;
break;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ IFilter::PreflightResult TriangleCentroidFilter::preflightImpl(const DataStructu
{
DataPath createArrayDataPath = pTriangleGeometryDataPath.createChildPath(faceAttributeMatrix->getName()).createChildPath(pCentroidsArrayName);
// Create the face areas DataArray Action and store it into the resultOutputActions
auto createArrayAction = std::make_unique<CreateArrayAction>(nx::core::DataType::float32, std::vector<usize>{triangleGeom->getNumberOfFaces()}, std::vector<usize>{3}, createArrayDataPath);
auto createArrayAction = std::make_unique<CreateArrayAction>(nx::core::DataType::float64, std::vector<usize>{triangleGeom->getNumberOfFaces()}, std::vector<usize>{3}, createArrayDataPath);
resultOutputActions.value().appendAction(std::move(createArrayAction));
}

Expand Down

0 comments on commit be6c1b9

Please sign in to comment.