#include #include "vtkObjectFactory.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //---------------------------------------------------------------------------- vtkStandardNewMacro( vtkMetaDataSet ); vtkCxxRevisionMacro(vtkMetaDataSet, "$Revision: 1.4 $"); //---------------------------------------------------------------------------- vtkMetaDataSet::vtkMetaDataSet() { this->DataSet = 0; this->ActorList = vtkActorCollection::New(); this->Time = -1; this->Property = 0; this->Type = vtkMetaDataSet::VTK_META_UNKNOWN; this->PickedPointId = -1; this->PickedCellId = -1; this->Name = ""; this->FilePath = ""; this->Initialize(); } //---------------------------------------------------------------------------- vtkMetaDataSet::~vtkMetaDataSet() { std::cout<<"deleting vtkMetaDataSet "<GetName()<DataSet) { this->DataSet->Delete(); } this->ActorList->Delete(); } //---------------------------------------------------------------------------- void vtkMetaDataSet::Initialize (void) { this->ActorList->RemoveAllItems(); // if (this->DataSet) // this->DataSet->GetPointData()->CopyScalarsOn(); } //---------------------------------------------------------------------------- const char* vtkMetaDataSet::GetName (void) const { return this->Name.c_str(); } //---------------------------------------------------------------------------- void vtkMetaDataSet::SetName (const char* name) { this->Name = name; } //---------------------------------------------------------------------------- const char* vtkMetaDataSet::GetTag (void) const { return this->Tag.c_str(); } //---------------------------------------------------------------------------- void vtkMetaDataSet::SetTag (const char* tag) { this->Tag = tag; } //---------------------------------------------------------------------------- const char* vtkMetaDataSet::GetFilePath (void) const { return this->FilePath.c_str(); } //---------------------------------------------------------------------------- void vtkMetaDataSet::SetFilePath (const char* path) { this->FilePath = path; } //---------------------------------------------------------------------------- void vtkMetaDataSet::SetDataSet (vtkDataSet* dataset) { if (this->DataSet == dataset) { return; } if (this->DataSet) { this->DataSet->UnRegister(this); } this->DataSet = dataset; if (this->DataSet) { this->DataSet->Register(this); } if (this->DataSet) { //this->DataSet->GetPointData()->CopyAllOn(); this->Initialize(); } this->Modified(); } //---------------------------------------------------------------------------- void vtkMetaDataSet::AddActor(vtkActor* actor) { if (actor) this->ActorList->AddItem(actor); } //---------------------------------------------------------------------------- void vtkMetaDataSet::RemoveActor(vtkActor* actor) { this->ActorList->RemoveItem(actor); } //---------------------------------------------------------------------------- vtkActor* vtkMetaDataSet::GetActor(unsigned int i) { return vtkActor::SafeDownCast (this->ActorList->GetItemAsObject(i)); } //---------------------------------------------------------------------------- unsigned int vtkMetaDataSet::GetNumberOfActors(void) const { return this->ActorList->GetNumberOfItems(); } //---------------------------------------------------------------------------- void vtkMetaDataSet::SetVisibility (bool visible) { for (unsigned int i=0; iGetNumberOfActors(); i++) this->SetActorVisibility (i, visible); } //---------------------------------------------------------------------------- int vtkMetaDataSet::GetVisibility (void) { bool ret = false; for (unsigned int i=0; iGetNumberOfActors(); i++) { if (this->GetActorVisibility(i)) { ret = true; break; } } return ret; } //---------------------------------------------------------------------------- void vtkMetaDataSet::SetActorVisibility (unsigned int it, bool visible) { vtkActor* actor = this->GetActor (it); if (actor) actor->SetVisibility (visible); } //---------------------------------------------------------------------------- int vtkMetaDataSet::GetActorVisibility (unsigned int it) { vtkActor* actor = this->GetActor (it); if (actor) return actor->GetVisibility (); return false; } void vtkMetaDataSet::ReadPointData (const char* filename, const char* name) { std::string ext = vtksys::SystemTools::GetFilenameLastExtension (filename); try { if (strcmp (ext.c_str(), ".pos") == 0) this->ReadPointData_pos (filename, name); else if (strcmp (ext.c_str(), ".pot") == 0) this->ReadPointData_pot (filename, name); else if (strcmp (ext.c_str(), ".at") == 0) this->ReadPointData_at (filename, name); else if (strcmp (ext.c_str(), ".bb") == 0) this->ReadPointData_bb (filename, name); else if (strcmp (ext.c_str(), ".tbb") == 0) this->ReadPointData_tbb (filename, name); else { vtkErrorMacro("Unrecognized type\n"); throw vtkErrorCode::UnrecognizedFileTypeError; } } catch (vtkErrorCode::ErrorIds error) { throw error; } if (this->GetDataSet()) this->GetDataSet()->Modified(); } void vtkMetaDataSet::ReadPointData_pos(const char* filename, const char* name) { std::ifstream file (filename ); char str[256]; if(file.fail()) { vtkWarningMacro(<<"File not found"<GetDataSet()); if (!pointset) { vtkWarningMacro(<<"this DataSet dows not handle this type of attributes"<SetNumberOfPoints(pointset->GetPoints()->GetNumberOfPoints()); int i=0; while(!file.fail() && iGetNumberOfPoints()) { file >> t; position[0] = t; file >> t; position[1] = t; file >> t; position[2] = t; points->SetPoint (i, position[0], position[1], position[2]); i++; } pointset->SetPoints(points); points->Delete(); file.close(); } void vtkMetaDataSet::ReadPointData_pot(const char* filename, const char* name) { std::ifstream file (filename ); char str[256]; if(file.fail()) { vtkWarningMacro(<<"File not found"<Allocate(this->GetDataSet()->GetNumberOfPoints()); file.getline (str, 30); file.getline (str, 30); int i=0; while(!file.fail() && iGetDataSet()->GetNumberOfPoints()) { i++; file >> potential; array->InsertNextValue (potential); } file.close(); if (!name) name = vtksys::SystemTools::GetFilenameName (filename).c_str(); array->SetName (name); if (i == this->GetDataSet()->GetNumberOfPoints()) this->GetDataSet()->GetPointData()->AddArray (array); array->Delete(); } void vtkMetaDataSet::ReadPointData_at(const char* filename, const char* name) { std::ifstream file (filename ); char str[256]; if(file.fail()) { vtkErrorMacro("File not found\n"); throw vtkErrorCode::FileNotFoundError; } double value; vtkDoubleArray* depolarisation = vtkDoubleArray::New(); vtkDoubleArray* repolarisation = vtkDoubleArray::New(); vtkDoubleArray* speed = vtkDoubleArray::New(); depolarisation->Allocate(this->GetDataSet()->GetNumberOfPoints()); repolarisation->Allocate(this->GetDataSet()->GetNumberOfPoints()); speed->Allocate(this->GetDataSet()->GetNumberOfPoints()); file.getline (str, 30); int i=0; while(!file.fail() && iGetDataSet()->GetNumberOfPoints()) { i++; file >> value; depolarisation->InsertNextValue (value); file >> value; repolarisation->InsertNextValue (value); file >> value; speed->InsertNextValue (value); } file.close(); depolarisation->SetName ("depolarisation"); repolarisation->SetName ("repolarisation"); speed->SetName ("speed"); if (i == this->GetDataSet()->GetNumberOfPoints()) { this->GetDataSet()->GetPointData()->AddArray (depolarisation); this->GetDataSet()->GetPointData()->AddArray (repolarisation); this->GetDataSet()->GetPointData()->AddArray (speed); } depolarisation->Delete(); repolarisation->Delete(); speed->Delete(); //this->GetDataSet()->Modified(); } void vtkMetaDataSet::ReadPointData_bb(const char* filename, const char* name) { std::ifstream file (filename ); char str[256]; if(file.fail()) { vtkErrorMacro("File not found\n"); throw vtkErrorCode::FileNotFoundError; } double orientation[3]; vtkDoubleArray* array = vtkDoubleArray::New(); array->SetNumberOfComponents(3); array->Allocate(this->GetDataSet()->GetNumberOfPoints()); file.getline (str, 30); int i=0; while(!file.fail() && iGetDataSet()->GetNumberOfPoints()) { i++; for (unsigned int j=0; j<3; j++) file >> orientation[j]; array->InsertNextTupleValue (orientation); } file.close(); if (!name) name = vtksys::SystemTools::GetFilenameName (filename).c_str(); array->SetName (name); if (i == this->GetDataSet()->GetNumberOfPoints()) this->GetDataSet()->GetPointData()->SetVectors (array); array->Delete(); } void vtkMetaDataSet::ReadPointData_tbb(const char* filename, const char* name) { std::ifstream file (filename ); char str[256]; std::cout<<"reading fibers for cells"<SetNumberOfComponents(3); array->Allocate(this->GetDataSet()->GetNumberOfCells()); //array->SetNumberOfTuples (this->GetDataSet()->GetNumberOfPoints()); file.getline (str, 30); std::cout<<"ncells : "<GetDataSet()->GetNumberOfCells()<GetDataSet()->GetNumberOfCells()) { i++; for (unsigned int j=0; j<3; j++) file >> orientation[j]; // std::cout<<"vector is " // <InsertNextTupleValue (orientation); } file.close(); if (!name) name = vtksys::SystemTools::GetFilenameName (filename).c_str(); array->SetName (name); std::cout<<"finish at: "<GetDataSet()->GetNumberOfCells()) this->GetDataSet()->GetCellData()->SetVectors (array); array->Delete(); } //---------------------------------------------------------------------------- void vtkMetaDataSet::Read (const char* filename) { vtkErrorMacro(""); throw vtkErrorCode::UserError; } //---------------------------------------------------------------------------- void vtkMetaDataSet::Write (const char* filename) { vtkErrorMacro(""); throw vtkErrorCode::UserError; } void vtkMetaDataSet::LinkFilters (void) { } //---------------------------------------------------------------------------- void vtkMetaDataSet::CopyInformation (vtkMetaDataSet* metadataset) { if (!metadataset) return; this->SetName (metadataset->GetName()); this->SetTime (metadataset->GetTime()); this->SetFilePath (metadataset->GetFilePath()); this->SetProperty (metadataset->GetProperty()); //add actors ?? this->SetTag(metadataset->GetTag()); } // //---------------------------------------------------------------------------- // void vtkMetaDataSet::ColorByArray(vtkDataArray* array, vtkScalarsToColors *lut) // { // if (array) // this->ColorByArray(array->GetName(), lut); // } // //---------------------------------------------------------------------------- // void vtkMetaDataSet::ColorByArray(unsigned int iter, vtkScalarsToColors *lut) // { // vtkDataArrayCollection* collection = vtkDataArrayCollection::New(); // this->GetArrayCollection (collection); // if(collection->GetItem (iter)) // this->ColorByArray(collection->GetItem (iter), lut); // } //---------------------------------------------------------------------------- void vtkMetaDataSet::ColorByArray(vtkDataArray* array) { if (!array) return; bool array_is_in_points = false; if (this->GetDataSet()->GetPointData()->HasArray(array->GetName())) { // int ret = this->DataSet->GetPointData()->SetActiveAttribute (array->GetName(), vtkDataSetAttributes::SCALARS); array_is_in_points = true; } for (int i=0; iActorList->GetNumberOfItems(); i++) { vtkActor* actor = this->GetActor (i); if (!actor) continue; vtkMapper* mapper = actor->GetMapper(); mapper->Modified(); // mapper->UseLookupTableScalarRangeOff(); if (!array_is_in_points) mapper->SetScalarModeToUseCellFieldData(); else { mapper->SetScalarModeToUsePointFieldData(); } vtkLookupTable* lut = array->GetLookupTable(); if (lut) { mapper->SetInterpolateScalarsBeforeMapping(1); lut->SetRange (array->GetRange()); mapper->SetLookupTable (lut); } mapper->SetScalarRange (array->GetRange()[0], array->GetRange()[1]); mapper->SelectColorArray (array->GetName()); } } //---------------------------------------------------------------------------- void vtkMetaDataSet::SetScalarVisibility(bool val) { for (int i=0; iActorList->GetNumberOfItems(); i++) { vtkActor* actor = this->GetActor (i); if (!actor) continue; vtkMapper* mapper = actor->GetMapper(); mapper->SetScalarVisibility(val); } } //---------------------------------------------------------------------------- void vtkMetaDataSet::ScalarVisibilityOn(void) { this->SetScalarVisibility (true); } //---------------------------------------------------------------------------- void vtkMetaDataSet::ScalarVisibilityOff(void) { this->SetScalarVisibility (false); } //---------------------------------------------------------------------------- void vtkMetaDataSet::GetArrayCollection(vtkDataArrayCollection* collection) { if (!collection) return; for (int i=0; iGetDataSet()->GetPointData()->GetNumberOfArrays(); i++) { collection->AddItem(this->GetDataSet()->GetPointData()->GetArray (i)); } for (int i=0; iGetDataSet()->GetCellData()->GetNumberOfArrays(); i++) { collection->AddItem(this->GetDataSet()->GetCellData()->GetArray (i)); } } //---------------------------------------------------------------------------- vtkDataArray* vtkMetaDataSet::GetArray (const char* name) { vtkDataArray* ret = NULL; vtkDataArrayCollection* arrays = vtkDataArrayCollection::New(); this->GetArrayCollection (arrays); for (int i=0; iGetNumberOfItems(); i++) { if (arrays->GetItem (i)->GetName() && (strcmp(arrays->GetItem (i)->GetName(), name) == 0)) { ret = arrays->GetItem (i); break; } } arrays->Delete(); return ret; } //---------------------------------------------------------------------------- void vtkMetaDataSet::PrintSelf(ostream& os, vtkIndent indent) { this->Superclass::PrintSelf(os,indent); os << indent << "Name \t: " << this->Name << endl; os << indent << "DataSet \t: " << (*this->DataSet) << endl; }