#include <vtkAppendPolyData.h>
vtkIdType SPV3D_Prs::cellid = 0;
-vtkIdType SPV3D_Prs::solidid = 0;
+vtkIdType SPV3D_Prs::nbsolid = 0;
+std::map<vtkIdType, const char*> SPV3D_Prs::vtkIdToEntry;
vtkSmartPointer<vtkMultiBlockDataSet> SPV3D_Prs::multiGEOMData = vtkSmartPointer<vtkMultiBlockDataSet>::New();
-static vtkIdType SPV3D_Prs::FromEntryToVtkId (const char* entry)
+SPV3D_EXPORTSPV3DData::SPV3D_EXPORTSPV3DData()
{
- char *str = new char[strlen(entry)+1];
- strcpy(str, entry);
+ nbsolid = 0;
+ _multiGEOMData = vtkSmartPointer<vtkMultiBlockDataSet>::New();
+ pqServer *serv(pqApplicationCore::instance()->getServerManagerModel()->findServer(pqServerResource("builtin:")));
+ pqObjectBuilder *builder(pqApplicationCore::instance()->getObjectBuilder());
+ _sourceProducer = builder->createSource("sources","PVTrivialProducer",serv);
+}
+void SPV3D_EXPORTSPV3DData::SetPolyData(vtkPolyData* ds)
+{
+ _multiGEOMData->SetBlock(nbsolid , ds);
+ nbsolid++;
+}
- const char delimiter[2] = ":";
+void SPV3D_EXPORTSPV3DData::SetPrs(vtkPolyData* ds; const char* entry)
+{
+ unsigned int id;
+ if (havePrs(entry, id))
+ return;
+ auto nbCells( ds->GetNumberOfCells() );
- char* token;
- token = strtok(str, delimiter);
+ vtkNew<vtkIdTypeArray> solidIdArray;
+ std::cout << "nb of cells: " <<nbCells <<std::endl;
+ solidIdArray->SetNumberOfComponents(1);
+ solidIdArray->SetNumberOfTuples( nbCells );
+ solidIdArray->SetName("Solid id");
- std::uint32_t ret(0);
+// vtkNew<vtkIdTypeArray> cellIdArray;
+// cellIdArray->SetNumberOfComponents(1);
+// cellIdArray->SetNumberOfTuples( nbCells );
+// cellIdArray->SetName("Edge id");
- while (token != NULL) {
- ret |= atoi(token);
- token = strtok(NULL, delimiter);
- }
+ vtkIdType *pt( solidIdArray->GetPointer(0) );
+ vtkIdType solidid = SPV3D_Prs::FromEntryToVtkId(GetEntry());
+ std::cout <<"Presolidid_from_src: " <<solidid << std::endl;
+ std::for_each(pt,pt+nbCells,[solidid](vtkIdType& elt) { elt = solidid;});
+// pt = cellIdArray->GetPointer(0);
+// std::for_each(pt,pt+nbCells,[](vtkIdType& elt) { elt = SPV3D_Prs::cellid;SPV3D_Prs::cellid++; });
- return static_cast<vtkIdType> (ret);
+ ds->GetCellData()->AddArray( solidIdArray );
+// ->GetCellData()->AddArray( cellIdArray );
+ SetPolyData(ds);
}
+void SPV3D_EXPORTSPV3DData::RemovePrs(const char* entry)
+{
+ unsigned int id;
+ if (!havePrs(entry, id))
+ {
+ std::cout << "Can not find solid " << entry<< std::endl;
+ }
+ return;
+ _multiGEOMData->RemoveBlock(id);
+}
+
+void SPV3D_EXPORTSPV3DData::updateSource() const
+{
+ vtkNew<vtkAppendPolyData> appendFilter;
+ std::cout <<"number of block: " << _multiGEOMData->GetNumberOfBlocks()<<std::endl;
+ for (unsigned int i = 0; i < _multiGEOMData->GetNumberOfBlocks(); ++i)
+ {
+ vtkPolyData* polyData = vtkPolyData::SafeDownCast(_multiGEOMData->GetBlock(i));
+ if (polyData)
+ {
+ appendFilter->AddInputData(polyData);
+ }
+ }
+ appendFilter->Update();
+ vtkNew<vtkPolyData> ds;
+ ds->ShallowCopy(appendFilter->GetOutput());
+
+ vtkSMProxy* producerBase = _sourceProducer->getProxy();
+ vtkSMSourceProxy *producer(vtkSMSourceProxy::SafeDownCast(producerBase));
+ vtkObjectBase *clientSideObject(producer->GetClientSideObject());
+ vtkPVTrivialProducer *clientSideObjectCast = vtkPVTrivialProducer::SafeDownCast(clientSideObject);
+ clientSideObjectCast->SetOutput(ds);
+ _sourceProducer->updatePipeline();
+ pqProxy *producerBase2( getPQProxy(producerBase) );
+ if(producerBase2 && !_name.empty())
+ producerBase2->rename( _name.c_str() );
+}
bool SPV3D_EXPORTSPV3DData::IsVisible() const
{
return GetRepresentation()->isVisible();
}
+bool SPV3D_EXPORTSPV3DData::SolidIsVisible(vtkidtype solid_id) const
+{
+ if( std::find(Hide_list.begin(), Hide_list.end(), solid_id) )
+ return false;
+ return true
+}
+
+bool SPV3D_EXPORTSPV3DData::havePrs(const char* entry, unsigned int & id)
+{
+ vtkIdType solid_id = SPV3D_Prs::FromEntryToVtkId(entry);
+ id = 0;
+ while (id < _multiGEOMData->GetNumberOfBlocks())
+ {
+ vtkPolyData* polyData = vtkPolyData::SafeDownCast(_multiGEOMData->GetBlock(id));
+ if (polyData)
+ {
+ vtkIdTypeArray* retrievedArray = vtkIdTypeArray::SafeDownCast(toto->GetCellData()->GetArray("Solid id"));
+ if (retrievedArray && retrievedArray->GetValue(0) == solid_id)
+ break;
+ }
+ id++;
+ }
+
+ if (id < _multiGEOMData->GetNumberOfBlocks())
+ return true;
+ else
+ return false;
+}
+
+void SPV3D_EXPORTSPV3DData::Hide(vtkditype solid_id)
+{
+ Hide_list.push_back(solid_id);
+}
+
void SPV3D_EXPORTSPV3DData::Hide() const
{
if( GetRepresentation() )
{
}
+vtkIdType SPV3D_Prs::FromEntryToVtkId (const char* entry)
+{
+ char *str = new char[strlen(entry)+1];
+ strcpy(str, entry);
+
+ const char delimiter[2] = ":";
+
+ char* token;
+ token = strtok(str, delimiter);
+
+ std::uint32_t ret(atoi(token));
+ token = strtok(NULL, delimiter);
+
+ while (token != NULL) {
+ ret <<=8;
+ ret |= atoi(token);
+ token = strtok(NULL, delimiter);
+ }
+
+ return static_cast<vtkIdType> (ret);
+}
+
+const char* SPV3D_Prs::FromVtkIdToEntry(vtkIdType id)
+{
+ int d = id & 0xFF;
+ std::uint32_t c_work = ( val & 0xFF00 ); int c = c_work >> 8;
+ std::uint32_t b_work = ( val & 0xFF0000 ); int b = b_work >> 16;
+ std::uint32_t a_work = ( val & 0xFF000000 ); int a = a_work >> 24;
+ std::string ret = std::to_string(a) + ":" + std::to_string(b) + ":" + std::to_string(c)+ ":" + std::to_string(d);
+ return ret.c_str();
+}
+
SPV3D_Prs *SPV3D_Prs::deepCopy() const
{
SPV3D_Prs *ret = new SPV3D_Prs( *this );
SPV3D_EXPORTSPV3DData *alreadyExistingSrc = nullptr;
alreadyExistingSrc = _view->isEntryAlreadyExist( GetEntry() );
- std::cout <<"ENtry: " <<GetEntry() << std::endl;
- std::cout <<"solid_id from entry: "<< SPV3D_Prs::FromEntryToVtkId(GetEntry());
+
if(alreadyExistingSrc && !alreadyExistingSrc->GetSourceProducer())
{
actor->GetMapper()->Update();
// cellIdArray->SetName("Edge id");
vtkIdType *pt( solidIdArray->GetPointer(0) );
- std::for_each(pt,pt+nbCells,[](vtkIdType& elt) { elt = SPV3D_Prs::solidid;});
+ vtkIdType solidid = SPV3D_Prs::FromEntryToVtkId(GetEntry());
+ SPV3D_Prs::vtkIdToEntry[solidid] = GetEntry();
+ std::cout <<"Presolidid_from_src: " <<solidid << std::endl;
+ std::for_each(pt,pt+nbCells,[solidid](vtkIdType& elt) { elt = solidid;});
// pt = cellIdArray->GetPointer(0);
// std::for_each(pt,pt+nbCells,[](vtkIdType& elt) { elt = SPV3D_Prs::cellid;SPV3D_Prs::cellid++; });
// ds4->GetCellData()->AddArray( cellIdArray );
////Add dataset to multiblock
//
- SPV3D_Prs::multiGEOMData->SetBlock(SPV3D_Prs::solidid, ds4);
+ SPV3D_Prs::multiGEOMData->SetBlock(SPV3D_Prs::nbsolid , ds4);
+ SPV3D_Prs::nbsolid ++;
//
- SPV3D_Prs::solidid++;
}
-
vtkNew<vtkAppendPolyData> appendFilter;
- std::cout <<"number of block" << SPV3D_Prs::multiGEOMData->GetNumberOfBlocks()<<std::endl;
+ std::cout <<"number of block: " << SPV3D_Prs::multiGEOMData->GetNumberOfBlocks()<<std::endl;
for (unsigned int i = 0; i < SPV3D_Prs::multiGEOMData->GetNumberOfBlocks(); ++i)
{
vtkPolyData* polyData = vtkPolyData::SafeDownCast(SPV3D_Prs::multiGEOMData->GetBlock(i));
pqPipelineSource *mySourceProducer(builder->createSource("sources","PVTrivialProducer",serv));
vtkSMProxy* producerBase = mySourceProducer->getProxy();
vtkSMSourceProxy *producer(vtkSMSourceProxy::SafeDownCast(producerBase));
- //producer->SetInput(ds4, 0);
vtkObjectBase *clientSideObject(producer->GetClientSideObject());
vtkPVTrivialProducer *clientSideObjectCast = vtkPVTrivialProducer::SafeDownCast(clientSideObject);
clientSideObjectCast->SetOutput(ds5);
class SPV3D_EXPORTSPV3DData
{
public:
- SPV3D_EXPORTSPV3DData() = default;
+ SPV3D_EXPORTSPV3DData():nbsolid(0),_multiGEOMData( vtkSmartPointer<vtkMultiBlockDataSet>::New()){};
SPV3D_EXPORTSPV3DData *deepCopy() { return new SPV3D_EXPORTSPV3DData(*this); }
+ void SetPrs(vtkPolyData* ds, const char* entry);
+ void SetPolyData(vtkPolyData* ds);
+ void RemovePrs(const char* entry);
void SetSourceProducer(pqPipelineSource *sourceProducer) const { _sourceProducer = sourceProducer; }
pqPipelineSource *GetSourceProducer() const { return _sourceProducer; }
void SetRepresentation(pqDataRepresentation *repr) const { _repr = repr; }
pqDataRepresentation *GetRepresentation() const { return _repr; }
+ void updateSource();
bool IsNull() const { return !_sourceProducer && !_repr; }
bool IsVisible() const;
+ bool havePrs(const char* entry, unsigned int & id);
void Hide() const;
+ void Hide(vtkIdType solid_id);
+ bool SolidIsVisible(vtkIdType solid_id) const;
+
private:
SPV3D_EXPORTSPV3DData(const SPV3D_EXPORTSPV3DData& other) = default;
private:
+ vtkSmartPointer<vtkMultiBlockDataSet> _multiGEOMData;
+ vtkIdType nbsolid;
+ std::list<vtkIdType> Hide_list;
mutable pqPipelineSource *_sourceProducer = nullptr;
mutable pqDataRepresentation *_repr = nullptr;
};
bool IsNull() const override;
static vtkIdType FromEntryToVtkId (const char*);
- // static const char* FromVtkIdToEntry (vtkIdType);
+ static const char* FromVtkIdToEntry (vtkIdType);
private:
//! Name attached to the displayable object in the study
std::string _name;
static vtkIdType cellid;
- static vtkIdType solidid;
+ static vtkIdType nbsolid;
+ static std::map<vtkIdType,const char*> vtkIdToEntry;
static vtkSmartPointer<vtkMultiBlockDataSet> multiGEOMData;
};