Skip to content
Snippets Groups Projects
Commit 10265d3b authored by Lars Bilke's avatar Lars Bilke
Browse files

Initial implementation of VtkMappedMeshSource.

parent 9754fc15
No related branches found
No related tags found
No related merge requests found
/**
* \file
* \author Lars Bilke
* \date 2014-08-12
* \brief Implementation of the VtkMappedMeshSource class.
*
* \copyright
* Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#include "VtkMappedMeshSource.h"
#include "VtkMappedMesh.h"
#include "VtkMeshNodalCoordinatesTemplate.h"
//#include "vtkCPExodusIIResultsArrayTemplate.h"
#include "logog/include/logog.hpp"
#include "vtkCellData.h"
#include "vtkDemandDrivenPipeline.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkDoubleArray.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
#include "vtkUnstructuredGrid.h"
namespace InSituLib {
vtkStandardNewMacro(VtkMappedMeshSource)
void VtkMappedMeshSource::PrintSelf(ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Mesh: " << (_mesh ? _mesh->getName() : "(none)") << endl;
}
VtkMappedMeshSource::VtkMappedMeshSource()
: NumberOfDimensions(0),
NumberOfNodes(0)
{
this->SetNumberOfInputPorts(0);
}
VtkMappedMeshSource::~VtkMappedMeshSource()
{
}
int VtkMappedMeshSource::ProcessRequest(
vtkInformation *request, vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA()))
return this->RequestData(request, inputVector, outputVector);
if(request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION()))
return this->RequestInformation(request, inputVector, outputVector);
return this->Superclass::ProcessRequest(request, inputVector, outputVector);
}
int VtkMappedMeshSource::RequestData(vtkInformation *,
vtkInformationVector **,
vtkInformationVector *outputVector)
{
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;
this->Points->Reset();
vtkNew<VtkMeshNodalCoordinatesTemplate<double> > nodeCoords;
nodeCoords->SetNodes(_mesh->getNodes());
this->Points->SetData(nodeCoords.GetPointer());
//this->GetNodalVars();
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());
//this->Cells->Reset();
// TODO
WARN("RequestData %d", nodeCoords->GetNumberOfTuples());
return 1;
}
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
/**
* \file
* \author Lars Bilke
* \date 2014-08-12
* \brief Definition of the VtkMappedMeshSource class.
*
* \copyright
* Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#ifndef _VTKMAPPEDMESHSOURCE
#define _VTKMAPPEDMESHSOURCE
#include "vtkUnstructuredGridAlgorithm.h"
#include "vtkNew.h" // For vtkNew
#include <string> // For std::string
#include <vector> // For std::vector
class vtkDataArrayCollection;
class vtkPointData;
class vtkPoints;
namespace MeshLib {
class Mesh;
}
namespace InSituLib {
class VtkMappedMeshSource : public vtkUnstructuredGridAlgorithm
{
public:
static VtkMappedMeshSource *New();
vtkTypeMacro(VtkMappedMeshSource, vtkUnstructuredGridAlgorithm)
virtual void PrintSelf(ostream &os, vtkIndent indent);
void SetMesh(const MeshLib::Mesh* mesh) { this->_mesh = mesh; this->Modified(); }
const MeshLib::Mesh* GetMesh() const { return _mesh; }
protected:
VtkMappedMeshSource();
~VtkMappedMeshSource();
int ProcessRequest(vtkInformation *request, vtkInformationVector **inputVector,
vtkInformationVector *outputVector);
int RequestData(vtkInformation *, vtkInformationVector **,
vtkInformationVector *);
int RequestInformation(vtkInformation *, vtkInformationVector **,
vtkInformationVector *);
private:
VtkMappedMeshSource(const VtkMappedMeshSource &); // Not implemented.
void operator=(const VtkMappedMeshSource &); // Not implemented.
const MeshLib::Mesh* _mesh;
int NumberOfDimensions;
int NumberOfNodes;
//int NumberOfElementBlocks;
std::vector<std::string> NodalVariableNames;
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
#endif //_VTKMAPPEDMESHSOURCE
...@@ -68,6 +68,30 @@ TEST_F(InSituMesh, MappedMesh) ...@@ -68,6 +68,30 @@ TEST_F(InSituMesh, MappedMesh)
ASSERT_EQ(0, vtkMesh->GetNumberOfPoints()); // No points are defined ASSERT_EQ(0, vtkMesh->GetNumberOfPoints()); // No points are defined
} }
TEST_F(InSituMesh, MappedMeshSource)
{
ASSERT_TRUE(mesh != nullptr);
vtkNew<InSituLib::VtkMappedMeshSource> vtkSource;
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());
// });
}
TEST(InSituLibNodalCoordinates, Init) TEST(InSituLibNodalCoordinates, Init)
{ {
const size_t subdivisions = 99; const size_t subdivisions = 99;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment