Desktop App Environment

#define vSP vtkSmartPointer    
#define vSPNew(Var, Type)    vSP<Type> Var = vSP<Type>::New();

auto savePoints = []( vSP<vtkPoints> pts, std::string filePath )
{
    vSPNew( result, vtkPolyData );
    vSPNew( resultPts, vtkPoints );
    vSPNew( resultVerts, vtkCellArray );
    for( int i = 0; i < pts->GetNumberOfPoints(); ++i )
    {
        PointStruct pt( pts->GetPoint(i) );
        resultPts->InsertNextPoint( pt.point );
        vtkIdType pts[1] = { i };
        resultVerts->InsertNextCell( 1, pts );
    }
    result->SetPoints( resultPts );
    result->SetVerts( resultVerts );
    result->Modified();

    vSPNew( writer, vtkXMLPolyDataWriter );
    writer->SetInputData( result );
    writer->SetFileName( filePath.c_str() );
    writer->Write();
};

VTK WASM

auto savePoints = []( vSP<vtkPoints> pts, std::string filePath )
{
    vSPNew( result, vtkPolyData );
    vSPNew( resultPts, vtkPoints );
    vSPNew( resultVerts, vtkCellArray );
    for( int i = 0; i < pts->GetNumberOfPoints(); ++i )
    {
        PointStruct pt( pts->GetPoint(i) );
        resultPts->InsertNextPoint( pt.point );
        vtkIdType pts[1] = { i };
        resultVerts->InsertNextCell( 1, pts );
    }
    result->SetPoints( resultPts );
    result->SetVerts( resultVerts );
    result->Modified();


    vSPNew( writer, vtkXMLPolyDataWriter );
    writer->SetInputData( result );
    writer->SetFileName( filePath.c_str() );
    writer->Write();


    // save model to local disk
    std::string fileName = filePath;
    char buffer[505] = {0};
    sprintf(buffer, "const shot = Module.FS.readFile( \"%s\" ); \
        const link = document.createElement('a'); \
        link.style.display = 'none'; \
        document.body.appendChild(link); \
        const blob = new Blob([shot]); \
        link.href = URL.createObjectURL(blob); \
        link.download = '%s'; \
        link.click(); \
        document.body.removeChild(link);",
            filePath.c_str(), fileName.c_str());
#ifdef __EMSCRIPTEN__
    LOG(INFO, "buffer: ", buffer);
    emscripten_run_script(buffer);
#endif
};

Categories: VTKWeb

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Tex To PDF
: convert the Latex file which suffix is tex to a PDF file

X
0
Would love your thoughts, please comment.x
()
x