| 2733 | // --------------------------------------------------------------------- |
| 2734 | |
| 2735 | void MyFrame::SaveCurrentMesh(const wxFileName& mesh_filename, bool should_decimate, double targetReduction) |
| 2736 | { |
| 2737 | vtkSmartPointer<vtkPolyData> mesh = vtkSmartPointer<vtkPolyData>::New(); |
| 2738 | this->system->GetAsMesh(mesh,this->render_settings); |
| 2739 | |
| 2740 | if (should_decimate) |
| 2741 | { |
| 2742 | vtkSmartPointer<vtkQuadricDecimation> dec = vtkSmartPointer<vtkQuadricDecimation>::New(); |
| 2743 | dec->SetInputData(mesh); |
| 2744 | dec->SetTargetReduction(targetReduction); |
| 2745 | dec->Update(); |
| 2746 | mesh->DeepCopy(dec->GetOutput()); |
| 2747 | } |
| 2748 | |
| 2749 | vtkSmartPointer<vtkPolyDataNormals> normals = vtkSmartPointer<vtkPolyDataNormals>::New(); |
| 2750 | normals->SetInputData(mesh); |
| 2751 | normals->SplittingOff(); |
| 2752 | normals->Update(); |
| 2753 | vtkPolyData* pd = normals->GetOutput(); |
| 2754 | |
| 2755 | if(mesh_filename.GetExt().Lower() == _T("obj")) |
| 2756 | { |
| 2757 | wxBusyCursor busy; |
| 2758 | wxFileOutputStream to_file(mesh_filename.GetFullPath()); |
| 2759 | wxTextOutputStream out(to_file); |
| 2760 | out << "# Output from Ready - https://github.com/GollyGang/ready\n"; |
| 2761 | pd->BuildCells(); |
| 2762 | for(vtkIdType iPt=0;iPt<pd->GetNumberOfPoints();iPt++) |
| 2763 | out << "v " << pd->GetPoint(iPt)[0] << " " << pd->GetPoint(iPt)[1] << " " << pd->GetPoint(iPt)[2] << "\n"; |
| 2764 | if(pd->GetPointData()->GetNormals()) |
| 2765 | { |
| 2766 | for(vtkIdType iPt=0;iPt<pd->GetNumberOfPoints();iPt++) |
| 2767 | out << "vn " << pd->GetPointData()->GetNormals()->GetTuple3(iPt)[0] << " " |
| 2768 | << pd->GetPointData()->GetNormals()->GetTuple3(iPt)[1] << " " |
| 2769 | << pd->GetPointData()->GetNormals()->GetTuple3(iPt)[2] << "\n"; |
| 2770 | } |
| 2771 | for(vtkIdType iCell=0;iCell<pd->GetPolys()->GetNumberOfCells();iCell++) |
| 2772 | { |
| 2773 | vtkSmartPointer<vtkIdList> ids = vtkSmartPointer<vtkIdList>::New(); |
| 2774 | pd->GetCellPoints(iCell, ids); |
| 2775 | out << "f"; |
| 2776 | if(pd->GetPointData()->GetNormals()) |
| 2777 | { |
| 2778 | for(vtkIdType iPt = 0; iPt < ids->GetNumberOfIds(); iPt++) |
| 2779 | out << " " << wxInt32(ids->GetId(iPt) + 1) << "//" << wxInt32(ids->GetId(iPt) + 1); // (OBJ indices are 1-based) |
| 2780 | } |
| 2781 | else |
| 2782 | { |
| 2783 | for(vtkIdType iPt = 0; iPt < ids->GetNumberOfIds(); iPt++) |
| 2784 | out << " " << wxInt32(ids->GetId(iPt) + 1); // (OBJ indices are 1-based) |
| 2785 | } |
| 2786 | out << "\n"; |
| 2787 | } |
| 2788 | } |
| 2789 | else if(mesh_filename.GetExt().Lower() == _T("vtp")) |
| 2790 | { |
| 2791 | wxBusyCursor busy; |
| 2792 | vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New(); |
nothing calls this directly
no test coverage detected