Skip to content

Commit

Permalink
Merge pull request #149 from yumin/discrete_group_op
Browse files Browse the repository at this point in the history
Refactor EntityGroupOp in discrete session to also handle domain set
  • Loading branch information
yumin committed Apr 20, 2015
2 parents fbcf35a + 55a6c39 commit ab56771
Show file tree
Hide file tree
Showing 14 changed files with 326 additions and 123 deletions.
4 changes: 4 additions & 0 deletions smtk/bridge/discrete/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ SET(DiscreteOperationFiles
operation/vtkSplitOperator.cxx
operation/vtkSplitOperatorBase.cxx
operation/vtkMasterPolyDataNormals.cxx
operation/vtkMaterialOperator.cxx
operation/vtkMaterialOperatorBase.cxx
operation/vtkMergeDuplicateCells.cxx
operation/vtkModelEntityGroupOperator.cxx
operation/vtkModelEntityGroupOperatorBase.cxx
Expand Down Expand Up @@ -86,6 +88,8 @@ SET(DiscreteModelHeaders
operation/vtkSplitOperator.h
operation/vtkSplitOperatorBase.h
operation/vtkMasterPolyDataNormals.h
operation/vtkMaterialOperator.h
operation/vtkMaterialOperatorBase.h
operation/vtkMergeDuplicateCells.h
operation/vtkModelEntityGroupOperator.h
operation/vtkModelEntityGroupOperatorBase.h
Expand Down
32 changes: 22 additions & 10 deletions smtk/bridge/discrete/Session.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,14 @@ smtk::model::Group Session::addMaterialToManager(
{
// Add material relations and arrangements
translated |= smtk::model::SESSION_ENTITY_ARRANGED;
if (material->GetNumberOfAssociations(vtkModelRegionType))
{ // Add regions to material
this->addEntities(result, material->NewIterator(vtkModelRegionType), AddEntityToGroupHelper(), relDepth - 1);
}
else if(material->GetNumberOfAssociations(vtkModelFaceType))
{ // Add faces to material group
this->addEntities(result, material->NewIterator(vtkModelFaceType), AddEntityToGroupHelper(), relDepth - 1);
}
}

// Add material properties:
Expand Down Expand Up @@ -1091,20 +1099,24 @@ smtk::model::Volume Session::addVolumeToManager(
smtk::model::ManagerPtr mgr,
int relDepth)
{
if (refVolume && !mgr->findEntity(uid, false))
if (refVolume)
{
smtk::model::Volume result(mgr->insertVolume(uid));
smtk::model::SessionInfoBits translated = smtk::model::SESSION_NOTHING;
if (relDepth >= 0)
smtk::model::Volume result;
// if there is a Volume already for refVolume, return it; otherwise, create one
if(mgr->findEntity(uid, false))
result = smtk::model::Volume(mgr, uid);
else
{
// Add refVolume relations and arrangements
this->addEntities(result, refVolume->NewAdjacentModelFaceIterator(), AddRawRelationHelper(), relDepth - 1);
this->addEntities(result, refVolume->NewIterator(vtkModelShellUseType), AddVolumeUseToVolumeHelper(), relDepth - 1);
result = mgr->insertVolume(uid);
if (relDepth >= 0)
{
// Add refVolume relations and arrangements
this->addEntities(result, refVolume->NewAdjacentModelFaceIterator(), AddRawRelationHelper(), relDepth - 1);
this->addEntities(result, refVolume->NewIterator(vtkModelShellUseType), AddVolumeUseToVolumeHelper(), relDepth - 1);
}
this->addProperties(result, refVolume);
}

this->addProperties(result, refVolume);
translated |= smtk::model::SESSION_PROPERTIES;

return result;
}
return smtk::model::Volume();
Expand Down
1 change: 1 addition & 0 deletions smtk/bridge/discrete/kernel/vtkModelMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class VTKSMTKDISCRETEMODEL_EXPORT vtkModelMaterial : public vtkModelEntity
virtual ~vtkModelMaterial();
static vtkModelMaterial* New();

friend class vtkMaterialOperatorBase;
// Description:
// Remove GeometricEntity from this material. It is assumed that it
// will be added to another material.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
#ifndef __vtkMaterialOperator_h
#define __vtkMaterialOperator_h

#include "vtkCmbDiscreteModelModule.h" // For export macro
#include "smtk/bridge/discrete/discreteSessionExports.h" // For export macro
#include "vtkMaterialOperatorBase.h"
#include "cmbSystemConfig.h"

#include <iostream>

Expand All @@ -34,7 +33,7 @@ class vtkDiscreteModelWrapper;
class vtkIdList;
class vtkModelEntity;

class VTKCMBDISCRETEMODEL_EXPORT vtkMaterialOperator : public vtkMaterialOperatorBase
class SMTKDISCRETESESSION_EXPORT vtkMaterialOperator : public vtkMaterialOperatorBase
{
public:
static vtkMaterialOperator * New();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ vtkMaterialOperatorBase::vtkMaterialOperatorBase()
this->ItemType = vtkModelMaterialType;
this->IsItemTypeSet = 1;
this->GeometricEntitiesToAdd = vtkIdList::New();
this->GeometricEntitiesToRemove = vtkIdList::New();
this->PreviousMaterialsOfGeometricEntities = vtkIdList::New();
}

Expand All @@ -39,6 +40,11 @@ vtkMaterialOperatorBase::~vtkMaterialOperatorBase()
this->GeometricEntitiesToAdd->Delete();
this->GeometricEntitiesToAdd = 0;
}
if(this->GeometricEntitiesToRemove)
{
this->GeometricEntitiesToRemove->Delete();
this->GeometricEntitiesToRemove = 0;
}
if(this->PreviousMaterialsOfGeometricEntities)
{
this->PreviousMaterialsOfGeometricEntities->Delete();
Expand Down Expand Up @@ -98,6 +104,24 @@ void vtkMaterialOperatorBase::ClearGeometricEntitiesToAdd()
this->GeometricEntitiesToAdd->Reset();
}

void vtkMaterialOperatorBase::RemoveModelGeometricEntity(
vtkIdType GeometricEntityId)
{
this->GeometricEntitiesToRemove->InsertUniqueId(GeometricEntityId);
}

void vtkMaterialOperatorBase::RemoveModelGeometricEntity(
vtkModelGeometricEntity* GeometricEntity)
{
this->RemoveModelGeometricEntity(GeometricEntity->GetUniquePersistentId());
}

void vtkMaterialOperatorBase::ClearGeometricEntitiesToRemove()
{
this->GeometricEntitiesToRemove->Reset();
}


bool vtkMaterialOperatorBase::Operate(vtkDiscreteModel* Model)
{
if(!this->AbleToOperate(Model))
Expand All @@ -107,8 +131,6 @@ bool vtkMaterialOperatorBase::Operate(vtkDiscreteModel* Model)

vtkModelMaterial* Material = this->GetMaterial(Model);
this->PreviousMaterialsOfGeometricEntities->Reset();
this->PreviousMaterialsOfGeometricEntities->SetNumberOfIds(
this->GeometricEntitiesToAdd->GetNumberOfIds());

for(vtkIdType i=0;i<this->GeometricEntitiesToAdd->GetNumberOfIds();i++)
{
Expand All @@ -127,19 +149,42 @@ bool vtkMaterialOperatorBase::Operate(vtkDiscreteModel* Model)
GeometricEntity = Face;
}
}
if(GeometricEntity)
if(GeometricEntity && GeometricEntity->GetMaterial() != Material)
{
vtkModelMaterial* PreviousMaterial = GeometricEntity->GetMaterial();
this->PreviousMaterialsOfGeometricEntities->SetId(
i, PreviousMaterial->GetUniquePersistentId());
if(PreviousMaterial)
this->PreviousMaterialsOfGeometricEntities->InsertUniqueId(
PreviousMaterial->GetUniquePersistentId());
Material->AddModelGeometricEntity(vtkModelGeometricEntity::SafeDownCast(Entity));
}
}
// remove entities
for(vtkIdType i=0;i<this->GeometricEntitiesToRemove->GetNumberOfIds();i++)
{
vtkModelEntity* Entity = Model->GetModelEntity(this->GeometricEntitiesToRemove->GetId(i));
vtkDiscreteModelGeometricEntity* GeometricEntity = 0;
vtkDiscreteModelRegion* Region = vtkDiscreteModelRegion::SafeDownCast(Entity);
if(Region)
{
GeometricEntity = Region;
}
else
{
this->PreviousMaterialsOfGeometricEntities->SetId(i, -1);
vtkDiscreteModelFace* Face = vtkDiscreteModelFace::SafeDownCast(Entity);
if(Face && Face->GetModelRegion(0) == NULL && Face->GetModelRegion(1) == NULL)
{ // Face can have a material associated with it since it is not associated with a region
GeometricEntity = Face;
}
}
if(GeometricEntity)
{
vtkModelMaterial* PreviousMaterial = GeometricEntity->GetMaterial();
if(PreviousMaterial == Material)
Material->RemoveModelGeometricEntity(vtkModelGeometricEntity::SafeDownCast(Entity));
}
}


return this->Superclass::Operate(Model);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,19 @@
// We may eventually need to add in the ability to set a
// warehouseid of a material here as well.

#ifndef __smtkdiscrete_vtkMaterialOperatorBase_h
#define __smtkdiscrete_vtkMaterialOperatorBase_h

#ifndef __vtkMaterialOperatorBase_h
#define __vtkMaterialOperatorBase_h

#include "vtkCmbDiscreteModelModule.h" // For export macro
#include "smtk/bridge/discrete/discreteSessionExports.h" // For export macro
#include "vtkModelEntityOperatorBase.h"
#include "cmbSystemConfig.h"

class vtkModelMaterial;
class vtkDiscreteModel;
class vtkIdList;
class vtkModelEntity;
class vtkModelGeometricEntity;

class VTKCMBDISCRETEMODEL_EXPORT vtkMaterialOperatorBase : public vtkModelEntityOperatorBase
class SMTKDISCRETESESSION_EXPORT vtkMaterialOperatorBase : public vtkModelEntityOperatorBase
{
public:
static vtkMaterialOperatorBase * New();
Expand Down Expand Up @@ -70,6 +68,13 @@ class VTKCMBDISCRETEMODEL_EXPORT vtkMaterialOperatorBase : public vtkModelEntity
// Get the list of GeometricEntitiesToAdd.
vtkGetObjectMacro(GeometricEntitiesToAdd, vtkIdList);

// Description:
// Remove Entities. This is not present in V3
void ClearGeometricEntitiesToRemove();
void RemoveModelGeometricEntity(vtkIdType GeometricEntityId);
void RemoveModelGeometricEntity(vtkModelGeometricEntity* GeometricEntity);
vtkGetObjectMacro(GeometricEntitiesToRemove, vtkIdList);

// Description:
// Get the list of PreviousMaterialsOfGeometricEntities.
vtkGetObjectMacro(PreviousMaterialsOfGeometricEntities, vtkIdList);
Expand Down Expand Up @@ -103,8 +108,9 @@ class VTKCMBDISCRETEMODEL_EXPORT vtkMaterialOperatorBase : public vtkModelEntity
void operator=(const vtkMaterialOperatorBase&); // Not implemented.

// Description:
// A list of vtkModelGeometricEntitys to add.
// A list of vtkModelGeometricEntitys to add/remove.
vtkIdList* GeometricEntitiesToAdd;
vtkIdList* GeometricEntitiesToRemove;

// Description:
// A list of the old materials that each vtkModelGeometricEntity
Expand Down
Loading

0 comments on commit ab56771

Please sign in to comment.