8 #include "PlusConfigure.h" 13 #include <vtkOBJReader.h> 14 #include <vtkPLYReader.h> 15 #include <vtkPolyData.h> 16 #include <vtkPolyDataReader.h> 17 #include <vtkSTLReader.h> 21 static const std::string GET_POLYDATA =
"GetPolydata";
48 if (aConfig->GetAttribute(
"FileName") !=
nullptr)
50 this->
PolydataId = aConfig->GetAttribute(
"FileName");
58 LOG_ERROR(
"Unable to find FileName attribute or metadata in " << this->GetName() <<
" command.");
68 if (this->GetPolydataId().empty())
70 LOG_ERROR(
"PolydataId not set when WriteConfiguration was called.");
73 aConfig->SetAttribute(
"FileName", this->GetPolydataId().c_str());
82 cmdNames.push_back(GET_POLYDATA);
89 if (commandName.empty() || igsioCommon::IsEqualInsensitive(commandName, GET_POLYDATA))
92 desc +=
"Acquire the polydata.";
100 SetName(GET_POLYDATA);
106 std::string baseMessage = std::string(
"vtkPlusGetPolydataCommand ") + (!this->
Name.empty() ? this->
Name :
"(undefined)")
107 +
", device: (" + (this->GetPolydataId().empty() ?
"(undefined)" : this->GetPolydataId()) +
")";
110 if (igsioCommon::IsEqualInsensitive(this->
Name, GET_POLYDATA))
127 vtkSmartPointer<vtkPolyDataReader> reader = vtkSmartPointer<vtkPolyDataReader>::New();
130 if (vtksys::SystemTools::FileExists(this->
PolydataId))
132 reader->SetFileName(this->
PolydataId.c_str());
138 reader->SetFileName(finalFileName.c_str());
142 LOG_ERROR(
"Unable to locate file with name " << this->
PolydataId);
148 vtkSmartPointer<vtkAbstractPolyDataReader> polyReader = vtkSmartPointer<vtkSTLReader>::New();
149 if (!reader->IsFilePolyData())
152 polyReader->SetFileName(finalFileName.c_str());
153 polyReader->Update();
154 if (polyReader->GetOutput() ==
nullptr)
156 polyReader = vtkSmartPointer<vtkOBJReader>::New();
157 polyReader->SetFileName(finalFileName.c_str());
158 polyReader->Update();
159 if (polyReader->GetOutput() ==
nullptr)
161 polyReader = vtkSmartPointer<vtkPLYReader>::New();
162 polyReader->SetFileName(finalFileName.c_str());
163 polyReader->Update();
164 if (polyReader->GetOutput() ==
nullptr)
166 LOG_ERROR(
"Unrecognized polydata file type: " << this->
PolydataId);
178 auto errorCode = (reader ==
nullptr ? polyReader->GetErrorCode() : reader->GetErrorCode());
179 vtkPolyData* polyData = (reader ==
nullptr ? polyReader->GetOutput() : reader->GetOutput());
182 std::stringstream ss;
183 ss <<
"Reader threw error: " << errorCode;
186 else if (polyData !=
nullptr)
188 vtkSmartPointer<vtkPlusCommandPolydataResponse> response = vtkSmartPointer<vtkPlusCommandPolydataResponse>::New();
189 response->SetClientId(this->
ClientId);
190 response->SetPolyDataName(this->GetPolydataId());
191 response->SetPolyData(polyData);
195 std::string name = vtksys::SystemTools::GetFilenameName(this->
PolydataId);
virtual void GetCommandNames(std::list< std::string > &cmdNames)
virtual void PrintSelf(ostream &os, vtkIndent indent)
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aConfig)
const char ** errorString
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)
virtual void PrintSelf(ostream &os, vtkIndent indent)
PlusStatus ExecutePolydataReply(std::string &outErrorString)
virtual std::string GetDescription(const std::string &commandName)
void SetNameToGetPolydata()
static vtkPlusConfig * GetInstance()
bool RespondWithCommandMessage
igtl::MessageBase::MetaDataMap MetaData
void QueueCommandResponse(PlusStatus status, const std::string &message, const std::string &error="", const igtl::MessageBase::MetaDataMap *metaData=nullptr)
virtual PlusStatus Execute()
PlusStatus FindModelPath(const std::string &aModelPath, std::string &aFoundAbsolutePath)
This command is used to answer the OpenIGTLink message GET_POLYDATA. GET_POLYDATA returns the request...
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aConfig)
vtkStandardNewMacro(vtkPlusGetPolydataCommand)
PlusCommandResponseList CommandResponseQueue
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)
vtkPlusGetPolydataCommand()
virtual ~vtkPlusGetPolydataCommand()