X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPlugins%2FTableReader%2FReader%2FvtkVisuTableReader.cxx;h=383eaaa16ee857ec17821b04991c8015ed59fc0a;hb=5b130b79009fb8c054f777569fbc7c609f92e266;hp=4a5e8c9ffbda4e0910e4a5855d1a058b0e26cd8a;hpb=f284847a1f9ec2519639285396adf10a84903eea;p=modules%2Fparavis.git diff --git a/src/Plugins/TableReader/Reader/vtkVisuTableReader.cxx b/src/Plugins/TableReader/Reader/vtkVisuTableReader.cxx index 4a5e8c9f..383eaaa1 100644 --- a/src/Plugins/TableReader/Reader/vtkVisuTableReader.cxx +++ b/src/Plugins/TableReader/Reader/vtkVisuTableReader.cxx @@ -40,13 +40,13 @@ using namespace std; vtkStandardNewMacro(vtkVisuTableReader); vtkVisuTableReader::vtkVisuTableReader(): - FileName(0) + FileName(0) { this->SetNumberOfInputPorts(0); this->SetNumberOfOutputPorts(1); this->FileName = NULL; - + this->DetectNumericColumns = true; this->FirstStringAsTitles = false; @@ -54,7 +54,7 @@ vtkVisuTableReader::vtkVisuTableReader(): this->ValueDelimiter = 0; this->SetValueDelimiter(" "); - + this->AvailableTables = vtkStringArray::New(); } @@ -74,131 +74,131 @@ void vtkVisuTableReader::PrintSelf(ostream& os, vtkIndent indent) { this->Superclass::PrintSelf(os, indent); os << indent << "FileName: " - << (this->FileName ? this->FileName : "(none)") << endl; + << (this->FileName ? this->FileName : "(none)") << endl; os << indent << "DetectNumericColumns: " - << (this->DetectNumericColumns? "true" : "false") << endl; + << (this->DetectNumericColumns? "true" : "false") << endl; os << indent << "ValueDelimiter: " - << (this->ValueDelimiter ? this->ValueDelimiter : "(none)") << endl; + << (this->ValueDelimiter ? this->ValueDelimiter : "(none)") << endl; os << indent << "TableNumber: " << this->TableNumber<< endl; } int vtkVisuTableReader::RequestData(vtkInformation*, - vtkInformationVector**, - vtkInformationVector* outputVector) + vtkInformationVector**, + vtkInformationVector* outputVector) { vtkTable* const output_table = vtkTable::GetData(outputVector); try + { + vtkInformation* const outInfo = outputVector->GetInformationObject(0); + if(outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER()) && + outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER()) > 0) { - vtkInformation* const outInfo = outputVector->GetInformationObject(0); - if(outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER()) && - outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER()) > 0) - { - return 1; - } - - // If the filename is not defined - if(!this->FileName || this->TableNumber < 0) - { - return 1; - } - - // Read table with the given number from the file - Table2D table = GetTable(this->FileName, this->ValueDelimiter, - this->TableNumber, this->FirstStringAsTitles); - - // Set table name - output_table->GetInformation()->Set(vtkDataObject::FIELD_NAME(), - table.myTitle.c_str()); - - int nbRows = table.myRows.size(); - int nbCols = table.myRows[0].myValues.size(); - - for (int col=0; col < nbCols; col++) - { - vtkStringArray* newCol = vtkStringArray::New(); - newCol->SetNumberOfValues(nbRows); - - // Set value - for (int row=0; row < nbRows; row++) - { - newCol->SetValue(row, table.myRows[row].myValues[col].c_str()); - } - - // Set title - bool hasUnit = !table.myColumnUnits[col].empty(); - - if (table.myColumnTitles[col].empty()) - { - vtksys_ios::stringstream buffer; - if (hasUnit) - { - buffer << col <<" [" << table.myColumnUnits[col].c_str() << "]"; - } - else - { - buffer << col; - } - newCol->SetName(buffer.str().c_str()); - } - else - { - if (hasUnit) - { - vtksys_ios::stringstream buffer; - buffer << table.myColumnTitles[col].c_str() - <<" [" << table.myColumnUnits[col].c_str() << "]"; - newCol->SetName(buffer.str().c_str()); - } - else - { - newCol->SetName(table.myColumnTitles[col].c_str()); - } - } - - output_table->AddColumn(newCol); - newCol->Delete(); - } - - // Detect numeric columns if needed - if (this->DetectNumericColumns) - { - vtkStringToNumeric* convertor = vtkStringToNumeric::New(); - vtkTable* clone = output_table->NewInstance(); - clone->ShallowCopy(output_table); - convertor->SetInputData(clone); - convertor->Update(); - clone->Delete(); - output_table->ShallowCopy(convertor->GetOutputDataObject(0)); - convertor->Delete(); - } - } - catch(vtksys_stl::exception& e) + return 1; + } + + // If the filename is not defined + if(!this->FileName || this->TableNumber < 0) { - vtkErrorMacro(<< "caught exception: " << e.what() << endl); - output_table->Initialize(); + return 1; } - catch(...) + + // Read table with the given number from the file + Table2D table = GetTable(this->FileName, this->ValueDelimiter, + this->TableNumber, this->FirstStringAsTitles); + + // Set table name + output_table->GetInformation()->Set(vtkDataObject::FIELD_NAME(), + table.myTitle.c_str()); + + int nbRows = table.myRows.size(); + int nbCols = table.myRows[0].myValues.size(); + + for (int col=0; col < nbCols; col++) { - vtkErrorMacro(<< "caught unknown exception." << endl); - output_table->Initialize(); + vtkStringArray* newCol = vtkStringArray::New(); + newCol->SetNumberOfValues(nbRows); + + // Set value + for (int row=0; row < nbRows; row++) + { + newCol->SetValue(row, table.myRows[row].myValues[col].c_str()); + } + + // Set title + bool hasUnit = !table.myColumnUnits[col].empty(); + + if (table.myColumnTitles[col].empty()) + { + vtksys_ios::stringstream buffer; + if (hasUnit) + { + buffer << col <<" [" << table.myColumnUnits[col].c_str() << "]"; + } + else + { + buffer << col; + } + newCol->SetName(buffer.str().c_str()); + } + else + { + if (hasUnit) + { + vtksys_ios::stringstream buffer; + buffer << table.myColumnTitles[col].c_str() + <<" [" << table.myColumnUnits[col].c_str() << "]"; + newCol->SetName(buffer.str().c_str()); + } + else + { + newCol->SetName(table.myColumnTitles[col].c_str()); + } + } + + output_table->AddColumn(newCol); + newCol->Delete(); } - + + // Detect numeric columns if needed + if (this->DetectNumericColumns) + { + vtkStringToNumeric* convertor = vtkStringToNumeric::New(); + vtkTable* clone = output_table->NewInstance(); + clone->ShallowCopy(output_table); + convertor->SetInputData(clone); + convertor->Update(); + clone->Delete(); + output_table->ShallowCopy(convertor->GetOutputDataObject(0)); + convertor->Delete(); + } + } + catch(vtksys_stl::exception& e) + { + vtkErrorMacro(<< "caught exception: " << e.what() << endl); + output_table->Initialize(); + } + catch(...) + { + vtkErrorMacro(<< "caught unknown exception." << endl); + output_table->Initialize(); + } + return 1; } vtkStringArray* vtkVisuTableReader::GetAvailableTables() { this->AvailableTables->Initialize(); - + vector titles = - GetTableNames(this->FileName, this->ValueDelimiter, - this->FirstStringAsTitles); - + GetTableNames(this->FileName, this->ValueDelimiter, + this->FirstStringAsTitles); + for(int i = 0; i < titles.size(); i++) - { - this->AvailableTables->InsertNextValue(titles[i].c_str()); - } - + { + this->AvailableTables->InsertNextValue(titles[i].c_str()); + } + return this->AvailableTables; }