Skip to content
Snippets Groups Projects
Select Git revision
  • 4fdd4d7adadb2ecda624c902b3dd08880a186e63
  • master default protected
  • alphashapes
  • quadMeshingTools
  • cygwin_conv_path
  • macos_arm64
  • add-transfiniteautomatic-to-geo
  • patch_releases_4_10
  • HierarchicalHDiv
  • isuruf-master-patch-63355
  • hyperbolic
  • hexdom
  • hxt_update
  • jf
  • 1618-pythonocc-and-gmsh-api-integration
  • octreeSizeField
  • hexbl
  • alignIrregularVertices
  • getEdges
  • patch_releases_4_8
  • isuruf-master-patch-51992
  • gmsh_4_11_0
  • gmsh_4_10_5
  • gmsh_4_10_4
  • gmsh_4_10_3
  • gmsh_4_10_2
  • gmsh_4_10_1
  • gmsh_4_10_0
  • gmsh_4_9_5
  • gmsh_4_9_4
  • gmsh_4_9_3
  • gmsh_4_9_2
  • gmsh_4_9_1
  • gmsh_4_9_0
  • gmsh_4_8_4
  • gmsh_4_8_3
  • gmsh_4_8_2
  • gmsh_4_8_1
  • gmsh_4_8_0
  • gmsh_4_7_1
  • gmsh_4_7_0
41 results

PViewDataIO.cpp

Blame
  • Forked from gmsh / gmsh
    Source project has a limited visibility.
    PViewDataIO.cpp 8.80 KiB
    // Gmsh - Copyright (C) 1997-2013 C. Geuzaine, J.-F. Remacle
    //
    // See the LICENSE.txt file for license information. Please report all
    // bugs and problems to the public mailing list <gmsh@geuz.org>.
    
    #include <stdio.h>
    #include <string.h>
    #include "GmshMessage.h"
    #include "GmshDefines.h"
    #include "Numeric.h"
    #include "PViewData.h"
    #include "adaptiveData.h"
    #include "OS.h"
    
    bool PViewData::writeSTL(const std::string &fileName)
    {
      FILE *fp = Fopen(fileName.c_str(), "w");
      if(!fp){
        Msg::Error("Unable to open file '%s'", fileName.c_str());
        return false;
      }
    
      if(!getNumTriangles() && !getNumQuadrangles()){
        Msg::Error("No surface elements to save");
        fclose(fp);
        return false;
      }
    
      int step = getFirstNonEmptyTimeStep();
    
      fprintf(fp, "solid Created by Gmsh\n");
      for(int ent = 0; ent < getNumEntities(step); ent++){
        for(int ele = 0; ele < getNumElements(step, ent); ele++){
          if(getDimension(step, ent, ele) != 2) continue;
          if(skipElement(step, ent, ele)) continue;
          int N = getNumNodes(step, ent, ele);
          if(N != 3 && N != 4) continue;
          double x[4], y[4], z[4], n[3];
          for(int i = 0; i < N; i++)
            getNode(step, ent, ele, i, x[i], y[i], z[i]);
          normal3points(x[0], y[0], z[0], x[1], y[1], z[1], x[2], y[2], z[2], n);
          if(N == 3){
            fprintf(fp, "facet normal %g %g %g\n", n[0], n[1], n[2]);
            fprintf(fp, "  outer loop\n");
            fprintf(fp, "    vertex %g %g %g\n", x[0], y[0], z[0]);
            fprintf(fp, "    vertex %g %g %g\n", x[1], y[1], z[1]);
            fprintf(fp, "    vertex %g %g %g\n", x[2], y[2], z[2]);
            fprintf(fp, "  endloop\n");
            fprintf(fp, "endfacet\n");
          }
          else{
            fprintf(fp, "facet normal %g %g %g\n", n[0], n[1], n[2]);
            fprintf(fp, "  outer loop\n");
            fprintf(fp, "    vertex %g %g %g\n", x[0], y[0], z[0]);
            fprintf(fp, "    vertex %g %g %g\n", x[1], y[1], z[1]);
            fprintf(fp, "    vertex %g %g %g\n", x[2], y[2], z[2]);
            fprintf(fp, "  endloop\n");
            fprintf(fp, "endfacet\n");
            fprintf(fp, "facet normal %g %g %g\n", n[0], n[1], n[2]);
            fprintf(fp, "  outer loop\n");
            fprintf(fp, "    vertex %g %g %g\n", x[0], y[0], z[0]);
            fprintf(fp, "    vertex %g %g %g\n", x[2], y[2], z[2]);
            fprintf(fp, "    vertex %g %g %g\n", x[3], y[3], z[3]);
            fprintf(fp, "  endloop\n");
            fprintf(fp, "endfacet\n");
          }
        }
      }
      fprintf(fp, "endsolid Created by Gmsh\n");