From c283d8a641f3324831be561d36400a325de7f6c5 Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Tue, 12 Aug 2014 14:00:41 +0200
Subject: [PATCH] VtkMappedMeshSource is working.

Remaining todo: point and cell data.
---
 InSituLib/VtkMappedMeshSource.cpp             | 43 +++----------------
 InSituLib/VtkMappedMeshSource.h               |  6 ---
 .../TestVtkMeshNodalCoordinatesTemplate.cpp   | 12 +-----
 3 files changed, 6 insertions(+), 55 deletions(-)

diff --git a/InSituLib/VtkMappedMeshSource.cpp b/InSituLib/VtkMappedMeshSource.cpp
index ab3ca1e98b5..ba23c01440e 100644
--- a/InSituLib/VtkMappedMeshSource.cpp
+++ b/InSituLib/VtkMappedMeshSource.cpp
@@ -30,6 +30,7 @@
 #include "vtkPointData.h"
 #include "vtkPoints.h"
 #include "vtkUnstructuredGrid.h"
+#include "vtkIdTypeArray.h"
 
 namespace InSituLib {
 
@@ -73,7 +74,6 @@ int VtkMappedMeshSource::RequestData(vtkInformation *,
 	vtkSmartPointer<vtkInformation> outInfo = outputVector->GetInformationObject(0);
 	vtkSmartPointer<vtkUnstructuredGrid> output = vtkUnstructuredGrid::SafeDownCast(
 	        outInfo->Get(vtkDataObject::DATA_OBJECT()));
-	//output->Allocate(nElems);
 
 	if (outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER()) > 0)
 		return 1;
@@ -84,7 +84,7 @@ int VtkMappedMeshSource::RequestData(vtkInformation *,
 	nodeCoords->SetNodes(_mesh->getNodes());
 	this->Points->SetData(nodeCoords.GetPointer());
 
-	//this->GetNodalVars();
+	// TODO nodal vals
 
 	vtkNew<VtkMappedMesh> elems;
 	elems->GetImplementation()->SetNodes(_mesh->getNodes());
@@ -93,11 +93,10 @@ int VtkMappedMeshSource::RequestData(vtkInformation *,
 	 // Use the mapped point container for the block points
 	elems->SetPoints(this->Points.GetPointer());
 
-	//this->Cells->Reset();
+	// TODO cell vals
 
-	// TODO
-
-	WARN("RequestData %d", nodeCoords->GetNumberOfTuples());
+	output->Allocate(elems->GetNumberOfCells());
+	output->ShallowCopy(elems.GetPointer());
 
 	return 1;
 }
@@ -105,42 +104,10 @@ int VtkMappedMeshSource::RequestData(vtkInformation *,
 int VtkMappedMeshSource::RequestInformation(
 	vtkInformation *, vtkInformationVector **, vtkInformationVector *)
 {
-	// TODO
-	//bool success(this->ExGetMetaData());
-	//return success ? 1 : 0;
 	this->NumberOfDimensions = 3;
 	this->NumberOfNodes = _mesh->getNNodes();
 
 	return 1;
 }
 
-bool VtkMappedMeshSource::GetCoords()
-{
-	this->Points->Reset();
-
-	vtkNew<VtkMeshNodalCoordinatesTemplate<double> > nodeCoords;
-	nodeCoords->SetNodes(_mesh->getNodes());
-	this->Points->SetData(nodeCoords.GetPointer());
-
-	return true;
-}
-
-bool VtkMappedMeshSource::GetElems()
-{
-	vtkNew<VtkMappedMesh> elems;
-	elems->GetImplementation()->SetNodes(_mesh->getNodes());
-	elems->GetImplementation()->SetElements(_mesh->getElements());
-
-	 // Use the mapped point container for the block points
-	elems->SetPoints(this->Points.GetPointer());
-
-	// Add the point data arrays
-	//elems->GetPointData()->ShallowCopy(this->PointData.GetPointer());
-
-	// Read the element variables (cell data)
-	//TODO
-
-	return true;
-}
-
 } // Namespace InSituLib
diff --git a/InSituLib/VtkMappedMeshSource.h b/InSituLib/VtkMappedMeshSource.h
index 3f1c7098a16..8d92b58452e 100644
--- a/InSituLib/VtkMappedMeshSource.h
+++ b/InSituLib/VtkMappedMeshSource.h
@@ -63,14 +63,8 @@ private:
 	std::vector<std::string> ElementVariableNames;
 	//std::vector<int> ElementBlockIds;
 
-	bool GetCoords();
 	vtkNew<vtkPoints> Points;
-
-	bool GetNodalVars();
 	vtkNew<vtkPointData> PointData;
-
-	bool GetElems();
-	vtkNew<vtkUnstructuredGrid> ElementData;
 };
 
 } // Namespace InSituLib
diff --git a/Tests/InSituLib/TestVtkMeshNodalCoordinatesTemplate.cpp b/Tests/InSituLib/TestVtkMeshNodalCoordinatesTemplate.cpp
index f0e8a0f280e..a7717f1d40e 100644
--- a/Tests/InSituLib/TestVtkMeshNodalCoordinatesTemplate.cpp
+++ b/Tests/InSituLib/TestVtkMeshNodalCoordinatesTemplate.cpp
@@ -76,20 +76,10 @@ TEST_F(InSituMesh, MappedMeshSource)
 	vtkSource->SetMesh(mesh);
 	vtkSource->UpdateInformation();
 	vtkSource->Update();
-
 	vtkUnstructuredGrid* output = vtkSource->GetOutput();
 
-	// There are n_elements^2 elements in the mesh.
-	//ASSERT_EQ(n_elements * n_elements, vtkSource->);
-
-	//ASSERT_EQ(subdivisions*subdivisions, output->GetNumberOfCells());
 	ASSERT_EQ((subdivisions+1)*(subdivisions+1), output->GetNumberOfPoints());
-
-	// All elements have maximum four neighbors.
-	//testAllElements([](MeshLib::Element const* const e, ...)
-	//	{
-	//	ASSERT_EQ(4u, e->getNNeighbors());
-	//	});
+	ASSERT_EQ(subdivisions*subdivisions, output->GetNumberOfCells());
 }
 
 TEST(InSituLibNodalCoordinates, Init)
-- 
GitLab