-// Copyright (C) 2010-2014 CEA/DEN, EDF R&D
+// Copyright (C) 2010-2016 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
#include "vtkExtractGroup.h"
#include "MEDFileFieldRepresentationTree.hxx"
+#include "vtkMEDReader.h"
#include "vtkAdjacentVertexIterator.h"
+#include "vtkDataArrayTemplate.h"
#include "vtkIntArray.h"
#include "vtkCellData.h"
#include "vtkPointData.h"
#include "vtkDemandDrivenPipeline.h"
#include "vtkDataObjectTreeIterator.h"
#include "vtkThreshold.h"
+#include "vtkMultiBlockDataGroupFilter.h"
+#include "vtkCompositeDataToUnstructuredGridFilter.h"
+#include "vtkInformationDataObjectMetaDataKey.h"
#include <map>
#include <deque>
vtkStandardNewMacro(vtkExtractGroup);
-vtkCxxSetObjectMacro(vtkExtractGroup, SIL, vtkMutableDirectedGraph);
-
///////////////////
class ExtractGroupStatus
bool vtkExtractGroup::vtkExtractGroupInternal::IsInformationOK(vtkInformation *info)
{
- if(!info->Has(vtkDataObject::SIL()))
+ // Check the information contain meta data key
+ if(!info->Has(vtkMEDReader::META_DATA()))
return false;
- vtkMutableDirectedGraph *sil(vtkMutableDirectedGraph::SafeDownCast(info->Get(vtkDataObject::SIL())));
+
+ // Recover Meta Data
+ vtkMutableDirectedGraph *sil(vtkMutableDirectedGraph::SafeDownCast(info->Get(vtkMEDReader::META_DATA())));
if(!sil)
return false;
int idNames(0);
return false;
}
+const char* vtkExtractGroup::GetGrpStart()
+{
+ return ExtractGroupGrp::START;
+}
+
+const char* vtkExtractGroup::GetFamStart()
+{
+ return ExtractGroupFam::START;
+}
+
const char *vtkExtractGroup::vtkExtractGroupInternal::getMeshName() const
{
return this->_mesh_name.c_str();
}
itFams->Delete();
}
- it0->Delete();
+ it0->Delete();
//
std::size_t szg(_groups.size()),szf(_fams.size());
if(szg==oldGrps.size() && szf==oldFams.size())
int vtkExtractGroup::RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
{
+// vtkUnstructuredGridAlgorithm::RequestInformation(request,inputVector,outputVector);
try
{
- //std::cerr << "########################################## vtkExtractGroup::RequestInformation ##########################################" << std::endl;
+// std::cerr << "########################################## vtkExtractGroup::RequestInformation ##########################################" << std::endl;
+// request->Print(cout);
vtkInformation *outInfo(outputVector->GetInformationObject(0));
- vtkInformation *inputInfo(inputVector[0]->GetInformationObject(0));//unfortunately inputInfo->Has(vtkDataObject::SIL) returns false... use executive to find it !
- //
- vtkExecutive *exe(GetExecutive());
- vtkAlgorithm *alg(this);
- vtkInformation *infoOnSIL(alg->GetOutputInformation(0));
- while(!vtkExtractGroup::vtkExtractGroupInternal::IsInformationOK(infoOnSIL))// skipping vtkPVPostFilter
- {
- if(exe->GetNumberOfInputConnections(0)<1)
- {
- vtkErrorMacro("No SIL Data available ! The source of this filter must be MEDReader !");
- return 0;
- }
- vtkExecutive *exe2(exe->GetInputExecutive(0,0));
- //
- alg=exe2->GetAlgorithm(); exe=exe2; infoOnSIL=alg->GetOutputInformation(0);
- }
- //
- this->SetSIL(vtkMutableDirectedGraph::SafeDownCast(infoOnSIL->Get(vtkDataObject::SIL())));
+ vtkInformation *inputInfo(inputVector[0]->GetInformationObject(0));
+ if(!vtkExtractGroup::vtkExtractGroupInternal::IsInformationOK(inputInfo))
+ {
+ vtkErrorMacro("No SIL Data available ! The source of this filter must be MEDReader !");
+ return 0;
+ }
+
+ this->SetSIL(vtkMutableDirectedGraph::SafeDownCast(inputInfo->Get(vtkMEDReader::META_DATA())));
this->Internal->loadFrom(this->SIL);
//this->Internal->printMySelf(std::cerr);
- outInfo->Set(vtkDataObject::SIL(),this->SIL);
}
catch(INTERP_KERNEL::Exception& e)
{
return 1;
}
+/*!
+ * Do not use vtkCxxSetObjectMacro macro because input mdg comes from an already managed in the pipeline just a ref on it.
+ */
+void vtkExtractGroup::SetSIL(vtkMutableDirectedGraph *mdg)
+{
+ if(this->SIL==mdg)
+ return ;
+ this->SIL=mdg;
+}
+
template<class CellPointExtractor>
-vtkDataSet *FilterFamilies(vtkDataSet *input, const std::set<int>& idsToKeep, bool insideOut, const char *arrNameOfFamilyField,
+vtkDataSet *FilterFamilies(vtkSmartPointer<vtkThreshold>& thres,
+ vtkDataSet *input, const std::set<int>& idsToKeep, bool insideOut, const char *arrNameOfFamilyField,
const char *associationForThreshold, bool& catchAll, bool& catchSmth)
{
- static const int VTK_DATA_ARRAY_DELETE=vtkDataArrayTemplate<double>::VTK_DATA_ARRAY_DELETE;
- static const char ZE_SELECTION_ARR_NAME[]="@@ZeSelection@@";
+ const int VTK_DATA_ARRAY_DELETE=vtkDataArrayTemplate<double>::VTK_DATA_ARRAY_DELETE;
+ const char ZE_SELECTION_ARR_NAME[]="@@ZeSelection@@";
vtkDataSet *output(input->NewInstance());
output->ShallowCopy(input);
- vtkSmartPointer<vtkThreshold> thres(vtkSmartPointer<vtkThreshold>::New());
thres->SetInputData(output);
vtkDataSetAttributes *dscIn(input->GetCellData()),*dscIn2(input->GetPointData());
vtkDataSetAttributes *dscOut(output->GetCellData()),*dscOut2(output->GetPointData());
//
double vMin(insideOut==0?1.:0.),vMax(insideOut==0?2.:1.);
thres->ThresholdBetween(vMin,vMax);
- // OK for the output
+ // OK for the output
//
CellPointExtractor cpe2(input);
vtkDataArray *da(cpe2.Get()->GetScalars(arrNameOfFamilyField));
{
try
{
- //std::cerr << "########################################## vtkExtractGroup::RequestData ##########################################" << std::endl;
+// std::cerr << "########################################## vtkExtractGroup::RequestData ##########################################" << std::endl;
+// request->Print(cout);
vtkInformation* inputInfo=inputVector[0]->GetInformationObject(0);
- vtkDataSet *input(vtkDataSet::SafeDownCast(inputInfo->Get(vtkDataObject::DATA_OBJECT())));
+ vtkMultiBlockDataSet *inputMB(vtkMultiBlockDataSet::SafeDownCast(inputInfo->Get(vtkDataObject::DATA_OBJECT())));
+ if(inputMB->GetNumberOfBlocks()!=1)
+ {
+ std::ostringstream oss; oss << "vtkExtractGroup::RequestData : input has not the right number of parts ! Expected 1 !";
+ if(this->HasObserver("ErrorEvent") )
+ this->InvokeEvent("ErrorEvent",const_cast<char *>(oss.str().c_str()));
+ else
+ vtkOutputWindowDisplayErrorText(const_cast<char *>(oss.str().c_str()));
+ vtkObject::BreakOnError();
+ return 0;
+ }
+ vtkDataSet *input(vtkDataSet::SafeDownCast(inputMB->GetBlock(0)));
vtkInformation *info(input->GetInformation());
vtkInformation *outInfo(outputVector->GetInformationObject(0));
- vtkDataSet *output(vtkDataSet::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT())));
+ vtkMultiBlockDataSet *output(vtkMultiBlockDataSet::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT())));
std::set<int> idsToKeep(this->Internal->getIdsToKeep());
// first shrink the input
bool catchAll,catchSmth;
- vtkDataSet *tryOnCell(FilterFamilies<CellExtractor>(input,idsToKeep,this->InsideOut,
- MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_CELL_NAME,"vtkDataObject::FIELD_ASSOCIATION_CELLS",catchAll,catchSmth));
+ vtkSmartPointer<vtkThreshold> thres1(vtkSmartPointer<vtkThreshold>::New()),thres2(vtkSmartPointer<vtkThreshold>::New());
+ vtkDataSet *tryOnCell(FilterFamilies<CellExtractor>(thres1,input,idsToKeep,this->InsideOut,
+ MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_CELL_NAME,"vtkDataObject::FIELD_ASSOCIATION_CELLS",catchAll,catchSmth));
if(tryOnCell)
- {
- if(catchAll)
- {
- output->ShallowCopy(tryOnCell);
- tryOnCell->Delete();//
- return 1;
- }
- else
- {
- if(catchSmth)
- {
- vtkDataSet *tryOnNode(FilterFamilies<PointExtractor>(tryOnCell,idsToKeep,this->InsideOut,
- MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_NODE_NAME,"vtkDataObject::FIELD_ASSOCIATION_POINTS",catchAll,catchSmth));
- if(tryOnNode && catchSmth)
- {
- output->ShallowCopy(tryOnNode);
- tryOnCell->Delete();
- tryOnNode->Delete();//
- return 1;
- }
- else
- {
- if(tryOnNode)
- tryOnNode->Delete();
- output->ShallowCopy(tryOnCell);
- tryOnCell->Delete();
- return 1;
- }
- }
- else
- {
- vtkDataSet *tryOnNode(FilterFamilies<PointExtractor>(input,idsToKeep,this->InsideOut,
- MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_NODE_NAME,"vtkDataObject::FIELD_ASSOCIATION_POINTS",catchAll,catchSmth));
- if(tryOnNode)
- {
- tryOnCell->Delete();
- output->ShallowCopy(tryOnNode);
- tryOnNode->Delete();
- return 1;
- }
- else
- {
- output->ShallowCopy(tryOnCell);
- tryOnCell->Delete();
- return 0;
- }
- }
- }
- }
+ {
+ if(catchAll)
+ {
+ output->SetBlock(0,tryOnCell);
+ tryOnCell->Delete();//
+ return 1;
+ }
+ else
+ {
+ if(catchSmth)
+ {
+ vtkDataSet *tryOnNode(FilterFamilies<PointExtractor>(thres2,input,idsToKeep,this->InsideOut,
+ MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_NODE_NAME,"vtkDataObject::FIELD_ASSOCIATION_POINTS",catchAll,catchSmth));
+ if(tryOnNode && catchSmth)
+ {
+ output->SetBlock(0,tryOnCell);
+ output->SetBlock(1,tryOnNode);
+ tryOnCell->Delete();
+ tryOnNode->Delete();
+ return 1;
+ }
+ else
+ {
+ if(tryOnNode)
+ tryOnNode->Delete();
+ output->SetBlock(0,tryOnCell);
+ tryOnCell->Delete();
+ return 1;
+ }
+ }
+ else
+ {
+ vtkDataSet *tryOnNode(FilterFamilies<PointExtractor>(thres1,input,idsToKeep,this->InsideOut,
+ MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_NODE_NAME,"vtkDataObject::FIELD_ASSOCIATION_POINTS",catchAll,catchSmth));
+ if(tryOnNode)
+ {
+ tryOnCell->Delete();
+ output->SetBlock(0,tryOnNode);
+ tryOnNode->Delete();
+ return 1;
+ }
+ else
+ {
+ output->SetBlock(0,tryOnNode);
+ tryOnCell->Delete();
+ return 0;
+ }
+ }
+ }
+ }
else
- {
- vtkDataSet *tryOnNode(FilterFamilies<PointExtractor>(input,idsToKeep,this->InsideOut,
- MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_NODE_NAME,"vtkDataObject::FIELD_ASSOCIATION_POINTS",catchAll,catchSmth));
- if(tryOnNode)
- {
- output->ShallowCopy(tryOnNode);
- tryOnNode->Delete();//
- return 1;
- }
- else
- {
- std::ostringstream oss; oss << "vtkExtractGroup::RequestData : The integer array with name \""<< MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_CELL_NAME;
- oss << "\" or \"" << MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_NODE_NAME << "\" does not exist ! The extraction of group and/or family is not possible !";
- if(this->HasObserver("ErrorEvent") )
- this->InvokeEvent("ErrorEvent",const_cast<char *>(oss.str().c_str()));
- else
- vtkOutputWindowDisplayErrorText(const_cast<char *>(oss.str().c_str()));
- vtkObject::BreakOnError();
- return 0;
- }
- }
+ {
+ vtkDataSet *tryOnNode(FilterFamilies<PointExtractor>(thres1,input,idsToKeep,this->InsideOut,
+ MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_NODE_NAME,"vtkDataObject::FIELD_ASSOCIATION_POINTS",catchAll,catchSmth));
+ if(tryOnNode)
+ {
+ output->ShallowCopy(tryOnNode);
+ tryOnNode->Delete();//
+ return 1;
+ }
+ else
+ {
+ std::ostringstream oss; oss << "vtkExtractGroup::RequestData : The integer array with name \""<< MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_CELL_NAME;
+ oss << "\" or \"" << MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_NODE_NAME << "\" does not exist ! The extraction of group and/or family is not possible !";
+ if(this->HasObserver("ErrorEvent") )
+ this->InvokeEvent("ErrorEvent",const_cast<char *>(oss.str().c_str()));
+ else
+ vtkOutputWindowDisplayErrorText(const_cast<char *>(oss.str().c_str()));
+ vtkObject::BreakOnError();
+ return 0;
+ }
+ }
}
catch(INTERP_KERNEL::Exception& e)
{
const char *vtkExtractGroup::GetGroupsFlagsArrayName(int index)
{
const char *ret(this->Internal->getKeyOfEntry(index));
- //std::cerr << "vtkExtractGroup::GetFieldsTreeArrayName(" << index << ") -> " << ret << std::endl;
+// std::cerr << "vtkExtractGroup::GetFieldsTreeArrayName(" << index << ") -> " << ret << std::endl;
return ret;
}
int vtkExtractGroup::GetGroupsFlagsArrayStatus(const char *name)
{
int ret((int)this->Internal->getStatusOfEntryStr(name));
- //std::cerr << "vtkExtractGroup::GetGroupsFlagsArrayStatus(" << name << ") -> " << ret << std::endl;
+// std::cerr << "vtkExtractGroup::GetGroupsFlagsArrayStatus(" << name << ") -> " << ret << std::endl;
return ret;
}
void vtkExtractGroup::SetGroupsFlagsStatus(const char *name, int status)
{
//std::cerr << "vtkExtractGroup::SetFieldsStatus(" << name << "," << status << ")" << std::endl;
+ if (GetNumberOfGroupsFlagsArrays()<1)
+ return;
this->Internal->setStatusOfEntryStr(name,(bool)status);
if(std::string(name)==GetGroupsFlagsArrayName(GetNumberOfGroupsFlagsArrays()-1))
this->Modified();