Changeset 6539 for vtkvis/branches
- Timestamp:
- Sep 13, 2016, 11:26:18 AM (8 years ago)
- Location:
- vtkvis/branches/1.8
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
vtkvis/branches/1.8
- Property svn:mergeinfo changed
/vtkvis/trunk merged: 6538
- Property svn:mergeinfo changed
-
vtkvis/branches/1.8/DataSet.cpp
r6388 r6539 6 6 */ 7 7 8 #include <cstdlib> 9 #include <cstdio> 8 10 #include <cassert> 9 11 #include <cstring> 10 12 #include <cfloat> 11 13 #include <cmath> 14 #include <strings.h> 15 #include <unistd.h> 12 16 13 17 #include <vtkCharArray.h> … … 88 92 if (_dataSet == NULL) 89 93 return; 90 91 vtkSmartPointer<vtkDataSetWriter> writer = vtkSmartPointer<vtkDataSetWriter>::New(); 92 93 writer->SetFileName(filename); 94 writer->SetInputData(_dataSet); 95 writer->Write(); 94 95 bool useXML = false; 96 size_t len = strlen(filename); 97 if (len > 4 && 98 strcasecmp(filename + len - 4, ".vtk") != 0) { 99 useXML = true; 100 } 101 102 if (useXML) { 103 vtkSmartPointer<vtkXMLDataSetWriter> writer = vtkSmartPointer<vtkXMLDataSetWriter>::New(); 104 105 writer->SetFileName(filename); 106 writer->SetInputData(_dataSet); 107 writer->Write(); 108 } else { 109 vtkSmartPointer<vtkDataSetWriter> writer = vtkSmartPointer<vtkDataSetWriter>::New(); 110 111 writer->SetFileName(filename); 112 writer->SetInputData(_dataSet); 113 writer->Write(); 114 } 96 115 } 97 116 … … 101 120 bool DataSet::setDataFile(const char *filename) 102 121 { 103 vtkSmartPointer<vtkDataSetReader> reader = vtkSmartPointer<vtkDataSetReader>::New(); 122 bool useXML = false; 123 size_t len = strlen(filename); 124 if (len > 4 && 125 strcasecmp(filename + len - 4, ".vtk") != 0) { 126 useXML = true; 127 } 128 129 if (useXML) { 130 vtkSmartPointer<vtkXMLGenericDataObjectReader> reader = vtkSmartPointer<vtkXMLGenericDataObjectReader>::New(); 104 131 105 132 #if defined(WANT_TRACE) && defined(DEBUG) 106 reader->DebugOn(); 107 #endif 108 109 reader->SetFileName(filename); 110 reader->ReadAllNormalsOn(); 111 reader->ReadAllTCoordsOn(); 112 reader->ReadAllScalarsOn(); 113 reader->ReadAllColorScalarsOn(); 114 reader->ReadAllVectorsOn(); 115 reader->ReadAllTensorsOn(); 116 reader->ReadAllFieldsOn(); 117 118 return setData(reader); 133 reader->DebugOn(); 134 #endif 135 136 reader->SetFileName(filename); 137 138 return setData(reader); 139 } else { 140 vtkSmartPointer<vtkDataSetReader> reader = vtkSmartPointer<vtkDataSetReader>::New(); 141 142 #if defined(WANT_TRACE) && defined(DEBUG) 143 reader->DebugOn(); 144 #endif 145 146 reader->SetFileName(filename); 147 reader->ReadAllNormalsOn(); 148 reader->ReadAllTCoordsOn(); 149 reader->ReadAllScalarsOn(); 150 reader->ReadAllColorScalarsOn(); 151 reader->ReadAllVectorsOn(); 152 reader->ReadAllTensorsOn(); 153 reader->ReadAllFieldsOn(); 154 155 return setData(reader); 156 } 119 157 } 120 158 … … 124 162 bool DataSet::setData(char *data, int nbytes) 125 163 { 126 vtkSmartPointer<vtkDataSetReader> reader = vtkSmartPointer<vtkDataSetReader>::New(); 127 vtkSmartPointer<vtkCharArray> dataSetString = vtkSmartPointer<vtkCharArray>::New(); 164 if (nbytes > 0 && data[0] == '<') { 165 // Use XML Reader 166 vtkSmartPointer<vtkXMLGenericDataObjectReader> reader = vtkSmartPointer<vtkXMLGenericDataObjectReader>::New(); 167 168 char tmpfile[32]; 169 strcpy(tmpfile, "/tmp/vtkvis-XXXXXX"); 170 int fid = mkstemp(tmpfile); 171 if (fid < 0) { 172 ERROR("mkstemp: %s", strerror(errno)); 173 return false; 174 } 175 if (write(fid, data, (size_t)nbytes) < 0) { 176 ERROR("write: %s", strerror(errno)); 177 remove(tmpfile); 178 close(fid); 179 return false; 180 } 128 181 129 182 #if defined(WANT_TRACE) && defined(DEBUG) 130 reader->DebugOn(); 131 dataSetString->DebugOn(); 132 #endif 133 134 dataSetString->SetArray(data, nbytes, 1); 135 reader->SetInputArray(dataSetString); 136 reader->ReadFromInputStringOn(); 137 reader->ReadAllNormalsOn(); 138 reader->ReadAllTCoordsOn(); 139 reader->ReadAllScalarsOn(); 140 reader->ReadAllColorScalarsOn(); 141 reader->ReadAllVectorsOn(); 142 reader->ReadAllTensorsOn(); 143 reader->ReadAllFieldsOn(); 144 145 return setData(reader); 183 reader->DebugOn(); 184 #endif 185 reader->SetFileName(tmpfile); 186 187 bool ret = setData(reader); 188 if (remove(tmpfile) < 0) { 189 ERROR("remove: %s", strerror(errno)); 190 } 191 close(fid); 192 193 return ret; 194 } else { 195 vtkSmartPointer<vtkDataSetReader> reader = vtkSmartPointer<vtkDataSetReader>::New(); 196 vtkSmartPointer<vtkCharArray> dataSetString = vtkSmartPointer<vtkCharArray>::New(); 197 198 #if defined(WANT_TRACE) && defined(DEBUG) 199 reader->DebugOn(); 200 dataSetString->DebugOn(); 201 #endif 202 203 dataSetString->SetArray(data, nbytes, 1); 204 reader->SetInputArray(dataSetString); 205 reader->ReadFromInputStringOn(); 206 reader->ReadAllNormalsOn(); 207 reader->ReadAllTCoordsOn(); 208 reader->ReadAllScalarsOn(); 209 reader->ReadAllColorScalarsOn(); 210 reader->ReadAllVectorsOn(); 211 reader->ReadAllTensorsOn(); 212 reader->ReadAllFieldsOn(); 213 214 return setData(reader); 215 } 146 216 } 147 217
Note: See TracChangeset
for help on using the changeset viewer.