Commit af275131 authored by Robert Maynard's avatar Robert Maynard

Redesign PointConnecvitity to be database storage agnostic.

So in theory we can properly implement a version of smtk::mesh that doesn't
use moab.
parent e2883890
......@@ -70,6 +70,7 @@ namespace smtk
class Collection;
class Interface;
class Allocator;
class ConnectivityStorage;
namespace moab
{
......@@ -184,6 +185,8 @@ namespace smtk
typedef smtk::shared_ptr< smtk::mesh::Collection > CollectionPtr;
typedef smtk::shared_ptr< smtk::mesh::Interface > InterfacePtr;
typedef smtk::shared_ptr< smtk::mesh::Allocator > AllocatorPtr;
typedef smtk::shared_ptr< smtk::mesh::ConnectivityStorage >
ConnectivityStoragePtr;
namespace moab
{
......
......@@ -14,7 +14,7 @@ set(meshSrcs
moab/Allocator.cxx
moab/CellTypeToType.cxx
moab/Interface.cxx
moab/PointConnectivityStorage.cxx
moab/ConnectivityStorage.cxx
moab/Readers.cxx
moab/Writers.cxx
)
......
......@@ -118,7 +118,9 @@ smtk::mesh::PointConnectivity CellSet::pointConnectivity( ) const
//----------------------------------------------------------------------------
smtk::mesh::PointConnectivity CellSet::pointConnectivity( std::size_t position ) const
{
return smtk::mesh::PointConnectivity(this->m_parent, this->m_range[position]);
smtk::mesh::HandleRange singleIndex;
singleIndex.insert(this->m_range[position]);
return smtk::mesh::PointConnectivity(this->m_parent, singleIndex);
}
//----------------------------------------------------------------------------
......
......@@ -29,8 +29,6 @@ namespace mesh {
struct ContainsFunctor;
class PointConnectivity;
class PointConnectivity;
//----------------------------------------------------------------------------
class SMTKCORE_EXPORT Allocator
{
......@@ -53,6 +51,37 @@ public:
};
//----------------------------------------------------------------------------
class SMTKCORE_EXPORT ConnectivityStorage
{
public:
//struct that holds the required information to compute what is the
//current cell when we are iterating.
struct IterationState
{
IterationState():
whichConnectivityVector(0),
ptrOffsetInVector(0)
{
}
std::size_t whichConnectivityVector;
std::size_t ptrOffsetInVector;
};
virtual void initTraversal( IterationState& state ) = 0;
virtual bool fetchNextCell( IterationState& state,
smtk::mesh::CellType& cellType,
int& numPts,
const smtk::mesh::Handle* &points) = 0;
virtual bool equal( ConnectivityStorage* other ) const = 0;
virtual std::size_t cellSize() const = 0;
virtual std::size_t vertSize() const = 0;
};
//----------------------------------------------------------------------------
class SMTKCORE_EXPORT Interface
{
......@@ -67,6 +96,12 @@ public:
//are than assigned to an existing mesh or new mesh
virtual smtk::mesh::AllocatorPtr allocator() = 0;
//----------------------------------------------------------------------------
//get back an efficient storage mechanism for a range of cells point
//connectivity. This allows for efficient iteration of cell connectivity, and
//conversion to other formats
virtual smtk::mesh::ConnectivityStoragePtr connectivityStorage(const smtk::mesh::HandleRange& cells) = 0;
//----------------------------------------------------------------------------
virtual smtk::mesh::Handle getRoot() const = 0;
......
......@@ -12,51 +12,21 @@
#include "smtk/mesh/Collection.h"
//needs to be designed to have virtual parent in smtk::mesh
#include "smtk/mesh/moab/PointConnectivityStorage.h"
#include "smtk/mesh/moab/ConnectivityStorage.h"
namespace smtk {
namespace mesh {
//----------------------------------------------------------------------------
class PointConnectivity::InternalStorageImpl : public
smtk::mesh::moab::PointConnectivityStorage
{
public:
InternalStorageImpl(const smtk::mesh::InterfacePtr& iface,
const smtk::mesh::HandleRange& cells):
smtk::mesh::moab::PointConnectivityStorage(iface,cells)
{
}
InternalStorageImpl(const smtk::mesh::InterfacePtr& iface,
const smtk::mesh::Handle& cell):
smtk::mesh::moab::PointConnectivityStorage(iface,cell)
{
}
};
//----------------------------------------------------------------------------
PointConnectivity::PointConnectivity(const smtk::mesh::CollectionPtr& parent,
const smtk::mesh::HandleRange& range):
m_parent(parent),
m_connectivity( new InternalStorageImpl(parent->interface(), range) ),
m_iteratorLocation()
{
}
//----------------------------------------------------------------------------
PointConnectivity::PointConnectivity(const smtk::mesh::CollectionPtr& parent,
const smtk::mesh::Handle& cell):
const smtk::mesh::HandleRange& range):
m_parent(parent),
m_connectivity( new InternalStorageImpl(parent->interface(), cell) ),
m_connectivity( parent->interface()->connectivityStorage(range) ),
m_iteratorLocation()
{
}
//----------------------------------------------------------------------------
PointConnectivity::PointConnectivity(const smtk::mesh::PointConnectivity& other):
m_parent(other.m_parent),
......
......@@ -16,6 +16,7 @@
#include "smtk/mesh/CellTypes.h"
#include "smtk/mesh/Handle.h"
#include "smtk/mesh/Interface.h"
namespace smtk {
namespace mesh {
......@@ -38,9 +39,6 @@ public:
PointConnectivity(const smtk::mesh::CollectionPtr& parent,
const smtk::mesh::HandleRange& range);
PointConnectivity(const smtk::mesh::CollectionPtr& parent,
const smtk::mesh::Handle& cell);
//Copy Constructor required for rule of 3
PointConnectivity(const PointConnectivity& other);
......@@ -78,29 +76,12 @@ public:
int& numPts,
const smtk::mesh::Handle* &points);
//struct that holds the required information to compute what is the
//current cell when we are iterating.
struct IterationState
{
IterationState():
whichConnectivityVector(0),
ptrOffsetInVector(0)
{
}
std::size_t whichConnectivityVector;
std::size_t ptrOffsetInVector;
};
private:
smtk::mesh::CollectionPtr m_parent;
class InternalStorageImpl;
smtk::shared_ptr< InternalStorageImpl > m_connectivity;
IterationState m_iteratorLocation;
smtk::mesh::ConnectivityStoragePtr m_connectivity;
smtk::mesh::ConnectivityStorage::IterationState m_iteratorLocation;
};
}
......
......@@ -8,7 +8,7 @@
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#include "smtk/mesh/moab/PointConnectivityStorage.h"
#include "smtk/mesh/moab/ConnectivityStorage.h"
#include "smtk/mesh/moab/CellTypeToType.h"
#include "smtk/mesh/moab/Interface.h"
......@@ -20,8 +20,8 @@ namespace moab {
//----------------------------------------------------------------------------
PointConnectivityStorage::PointConnectivityStorage(
const smtk::mesh::InterfacePtr& interface,
ConnectivityStorage::ConnectivityStorage(
::moab::Interface* iface,
const smtk::mesh::HandleRange& cells):
ConnectivityStartPositions(),
ConnectivityArraysLengths(),
......@@ -37,8 +37,6 @@ PointConnectivityStorage::PointConnectivityStorage(
smtk::mesh::HandleRange::const_iterator cells_current = cells.begin();
smtk::mesh::HandleRange::const_iterator cells_end = cells.end();
::moab::Interface* m_iface = smtk::mesh::moab::extract_moab_interface(interface);
//We allocate VertConnectivityStorage once before we insert any vertices
//this gaurentees that all of the ConnectivityStartPositions pointers
//into our storage are valid. Otherwise the realloc's will cause
......@@ -51,7 +49,7 @@ PointConnectivityStorage::PointConnectivityStorage(
//the vertices first so, if cells_current isnt a vertice
//we have none
while(cells_current != cells_end &&
m_iface->type_from_handle(*cells_current) == ::moab::MBVERTEX)
iface->type_from_handle(*cells_current) == ::moab::MBVERTEX)
{
smtk::mesh::HandleRange::iterator verts_start = cells_current.start_of_block();
......@@ -85,11 +83,11 @@ PointConnectivityStorage::PointConnectivityStorage(
int numVertsPerCell=0, numCellsInSubRange=0;
::moab::ErrorCode result =
m_iface->connect_iterate(cells_current,
cells.end(),
connectivity,
numVertsPerCell,
numCellsInSubRange);
iface->connect_iterate(cells_current,
cells.end(),
connectivity,
numVertsPerCell,
numCellsInSubRange);
if(result == ::moab::MB_SUCCESS)
{
......@@ -98,7 +96,7 @@ PointConnectivityStorage::PointConnectivityStorage(
this->ConnectivityVertsPerCell.push_back(numVertsPerCell);
//fetch the current cell type for this block
::moab::EntityType moabCellType = m_iface->type_from_handle(*cells_current);
::moab::EntityType moabCellType = iface->type_from_handle(*cells_current);
this->ConnectivityTypePerCell.push_back(
smtk::mesh::moab::moabToSMTKCell( static_cast< int >(moabCellType) ) );
......@@ -133,61 +131,21 @@ PointConnectivityStorage::PointConnectivityStorage(
}
//----------------------------------------------------------------------------
PointConnectivityStorage::PointConnectivityStorage(
const smtk::mesh::InterfacePtr& interface,
const smtk::mesh::Handle& cell):
ConnectivityStartPositions(),
ConnectivityArraysLengths(),
ConnectivityVertsPerCell(),
ConnectivityTypePerCell(),
NumberOfCells(0),
NumberOfVerts(0),
VertConnectivityStorage()
ConnectivityStorage::~ConnectivityStorage( )
{
::moab::Interface* m_iface = smtk::mesh::moab::extract_moab_interface(interface);
const ::moab::EntityHandle* connectivity;
int numVertsPerCell=0;
const int numCellsInSubRange=1; //we are only passed a single cell
//we have none
::moab::EntityType moabCellType = m_iface->type_from_handle(cell);
if(moabCellType == ::moab::MBVERTEX)
{
//add to the VertConnectivityStorage the ids of the vertices in this
//range
this->VertConnectivityStorage.resize(1, cell);
connectivity = &(this->VertConnectivityStorage[0]);
numVertsPerCell = 1;
}
else
{
m_iface->get_connectivity(cell, connectivity, numVertsPerCell);
}
this->ConnectivityStartPositions.push_back(connectivity);
this->ConnectivityArraysLengths.push_back(numCellsInSubRange);
this->ConnectivityVertsPerCell.push_back(numVertsPerCell);
this->ConnectivityTypePerCell.push_back(
smtk::mesh::moab::moabToSMTKCell( static_cast< int >(moabCellType) ) );
this->NumberOfCells = numCellsInSubRange;
this->NumberOfVerts = numVertsPerCell;
}
//----------------------------------------------------------------------------
void PointConnectivityStorage::initTraversal(
smtk::mesh::PointConnectivity::IterationState& state )
void ConnectivityStorage::initTraversal(
smtk::mesh::ConnectivityStorage::IterationState& state )
{
state.whichConnectivityVector = 0;
state.ptrOffsetInVector = 0;
}
//----------------------------------------------------------------------------
bool PointConnectivityStorage::fetchNextCell(
smtk::mesh::PointConnectivity::IterationState& state,
bool ConnectivityStorage::fetchNextCell(
smtk::mesh::ConnectivityStorage::IterationState& state,
smtk::mesh::CellType& cellType,
int& numPts,
const smtk::mesh::Handle* &points)
......@@ -224,9 +182,14 @@ bool PointConnectivityStorage::fetchNextCell(
}
//----------------------------------------------------------------------------
bool PointConnectivityStorage::equal( PointConnectivityStorage* other ) const
bool ConnectivityStorage::equal( smtk::mesh::ConnectivityStorage* base_other ) const
{
if( this == other ) { return true;}
if( this == base_other ) { return true;}
if( !base_other ) { return false; }
smtk::mesh::moab::ConnectivityStorage* other =
dynamic_cast< smtk::mesh::moab::ConnectivityStorage* >(base_other);
if( !other ) { return false; }
//two quick checks that can confirm two items aren't equal
if( this->NumberOfCells != other->NumberOfCells )
......
......@@ -8,42 +8,46 @@
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#ifndef __smtk_mesh_moab_PointConnectivityStorage_h
#define __smtk_mesh_moab_PointConnectivityStorage_h
#ifndef __smtk_mesh_moab_ConnectivityStorage_h
#define __smtk_mesh_moab_ConnectivityStorage_h
#include "smtk/PublicPointerDefs.h"
#include "smtk/mesh/Handle.h"
#include "smtk/mesh/PointConnectivity.h"
#include "smtk/mesh/moab/Interface.h"
namespace smtk {
namespace mesh {
namespace moab {
class PointConnectivityStorage
class SMTKCORE_EXPORT ConnectivityStorage : public smtk::mesh::ConnectivityStorage
{
public:
PointConnectivityStorage(const smtk::mesh::InterfacePtr& iface,
const smtk::mesh::HandleRange& cells);
PointConnectivityStorage(const smtk::mesh::InterfacePtr& iface,
const smtk::mesh::Handle& cell);
ConnectivityStorage(::moab::Interface* interface,
const smtk::mesh::HandleRange& cells);
virtual ~ConnectivityStorage();
void initTraversal( smtk::mesh::PointConnectivity::IterationState& state );
void initTraversal( smtk::mesh::ConnectivityStorage::IterationState& state );
bool fetchNextCell( smtk::mesh::PointConnectivity::IterationState& state,
bool fetchNextCell( smtk::mesh::ConnectivityStorage::IterationState& state,
smtk::mesh::CellType& cellType,
int& numPts,
const smtk::mesh::Handle* &points);
bool equal( PointConnectivityStorage* other ) const;
bool equal( smtk::mesh::ConnectivityStorage* other ) const;
std::size_t cellSize() const { return NumberOfCells; }
std::size_t vertSize() const { return NumberOfVerts; }
private:
//blank since we are used by shared_ptr
ConnectivityStorage( const ConnectivityStorage& other );
//blank since we are used by shared_ptr
ConnectivityStorage& operator=( const ConnectivityStorage& other );
std::vector< const smtk::mesh::Handle* > ConnectivityStartPositions;
std::vector<int> ConnectivityArraysLengths;
std::vector<int> ConnectivityVertsPerCell;
......
......@@ -18,7 +18,7 @@
#include "smtk/mesh/moab/CellTypeToType.h"
#include "smtk/mesh/moab/Allocator.h"
#include "smtk/mesh/moab/PointConnectivityStorage.h"
#include "smtk/mesh/moab/ConnectivityStorage.h"
#include "moab/Core.hpp"
#include "moab/FileOptions.hpp"
......@@ -225,12 +225,25 @@ Interface::~Interface()
{
}
//----------------------------------------------------------------------------
smtk::mesh::AllocatorPtr Interface::allocator()
{
return this->m_alloc;
}
//----------------------------------------------------------------------------
smtk::mesh::ConnectivityStoragePtr Interface::connectivityStorage(
const smtk::mesh::HandleRange& cells)
{
//make boost shared_ptr
smtk::mesh::ConnectivityStoragePtr cs(
new smtk::mesh::moab::ConnectivityStorage(this->m_iface.get(),
cells) );
return cs;
}
//----------------------------------------------------------------------------
smtk::mesh::Handle Interface::getRoot() const
......
......@@ -64,6 +64,12 @@ public:
//are than assigned to an existing mesh or new mesh
smtk::mesh::AllocatorPtr allocator();
//----------------------------------------------------------------------------
//get back an efficient storage mechanism for a range of cells point
//connectivity. This allows for efficient iteration of cell connectivity, and
//conversion to other formats
virtual smtk::mesh::ConnectivityStoragePtr connectivityStorage(const smtk::mesh::HandleRange& cells);
//----------------------------------------------------------------------------
smtk::mesh::Handle getRoot() const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment