Skip to content

Commit b6e7993

Browse files
jourdainkwrobot
authored andcommitted
Merge topic 'improve-vtkjs-export'
9cdb120 Fix vtkJSONDataSetWriter with invalid field name efe773e ENH: vtkjs HTML bundling use data file path for html output Acked-by: Kitware Robot <[email protected]> Merge-request: !5363
2 parents 909aca6 + 9cdb120 commit b6e7993

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

IO/Export/vtkJSONDataSetWriter.cxx

+16-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ vtkStandardNewMacro(vtkJSONDataSetWriter);
4444
vtkJSONDataSetWriter::vtkJSONDataSetWriter()
4545
{
4646
this->FileName = nullptr;
47+
this->ValidStringCount = 1;
4748
}
4849

4950
// ----------------------------------------------------------------------------
@@ -142,7 +143,7 @@ std::string vtkJSONDataSetWriter::WriteArray(
142143
std::stringstream ss;
143144
ss << "{\n"
144145
<< INDENT << " \"vtkClass\": \"" << className << "\",\n"
145-
<< INDENT << " \"name\": \"" << (arrayName == nullptr ? array->GetName() : arrayName) << "\",\n"
146+
<< INDENT << " \"name\": \"" << this->GetValidString(arrayName == nullptr ? array->GetName() : arrayName) << "\",\n"
146147
<< INDENT << " \"numberOfComponents\": " << array->GetNumberOfComponents() << ",\n"
147148
<< INDENT << " \"dataType\": \"" << vtkJSONDataSetWriter::GetShortType(array, needConvert) << "Array\",\n"
148149
<< INDENT << " \"ref\": {\n"
@@ -387,6 +388,20 @@ std::string vtkJSONDataSetWriter::GetUID(vtkDataArray* input, bool& needConversi
387388

388389
// ----------------------------------------------------------------------------
389390

391+
std::string vtkJSONDataSetWriter::GetValidString(const char* name)
392+
{
393+
if (name != nullptr && strlen(name))
394+
{
395+
return name;
396+
}
397+
std::stringstream ss;
398+
ss << "invalid_" << this->ValidStringCount++;
399+
400+
return ss.str();
401+
}
402+
403+
// ----------------------------------------------------------------------------
404+
390405
bool vtkJSONDataSetWriter::WriteArrayAsRAW(vtkDataArray* input, const char* filePath)
391406
{
392407
if (input->GetDataTypeSize() == 0)

IO/Export/vtkJSONDataSetWriter.h

+8
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ class VTKIOEXPORT_EXPORT vtkJSONDataSetWriter : public vtkWriter
7272
static std::string GetUID(vtkDataArray*, bool& needConversion);
7373
//@}
7474

75+
//@{
76+
/**
77+
* Return a Unique identifier for any invalid string
78+
*/
79+
std::string GetValidString(const char*);
80+
//@}
81+
7582
//@{
7683
/**
7784
* Write the content of the vtkDataArray to disk based on the filePath
@@ -117,6 +124,7 @@ class VTKIOEXPORT_EXPORT vtkJSONDataSetWriter : public vtkWriter
117124

118125
char* FileName;
119126
bool ValidDataSet;
127+
int ValidStringCount;
120128

121129
int FillInputPortInformation(int port, vtkInformation* info) override;
122130

Web/Python/vtkmodules/web/vtkjs_helper.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def convertDirectoryToZipFile(directoryPath):
3535

3636
def addDataToViewer(dataPath, srcHtmlPath):
3737
if os.path.isfile(dataPath) and os.path.exists(srcHtmlPath):
38-
dstHtmlPath = '%s.html' % os.path.basename(dataPath)[:-6]
38+
dstDir = os.path.dirname(dataPath)
39+
dstHtmlPath = os.path.join(dstDir, '%s.html' % os.path.basename(dataPath)[:-6])
3940

4041
# Extract data as base64
4142
with open(dataPath, 'rb') as data:

0 commit comments

Comments
 (0)