Author: Tatiana Malygina <merlettaia@gmail.com>
Last-Update: 2016-06-07
Description: remove ply.h and ply.C completely from concavity

--- a/pkgs/R3Shapes/R3Mesh.C
+++ b/pkgs/R3Shapes/R3Mesh.C
@@ -6,7 +6,6 @@
 // Include files
 
 #include "R3Shapes/R3Shapes.h"
-#include "ply.h"
 
 
 
@@ -1985,8 +1984,6 @@
     nfaces = ReadOffFile(filename);
   else if (!strncmp(extension, ".ray", 4)) 
     nfaces = ReadRayFile(filename);
-  else if (!strncmp(extension, ".ply", 4)) 
-    nfaces = ReadPlyFile(filename);
   else if (!strncmp(extension, ".cat", 4)) 
     nfaces = ReadCattFile(filename);
   else if (!strncmp(extension, ".ifs", 4)) 
@@ -2305,180 +2302,6 @@
 
 
 
-int R3Mesh::
-ReadPlyFile(const char *filename)
-{
-  FILE *fp;
-  int i,j;
-  PlyFile *ply;
-  int nelems;
-  PlyProperty **plist;
-  char **elist;
-  int file_type;
-  int nprops;
-  int num_elems;
-  char *elem_name;
-  float version;
-
-  typedef struct PlyVertex {
-    float x, y, z;
-    float nx, ny, nz;
-  } PlyVertex;
-
-  typedef struct PlyFace {
-    unsigned char nverts;
-    int *verts;
-    int material;
-    int segment;
-  } PlyFace;
-
-  // List of property information for a vertex 
-  static PlyProperty vert_props[] = { 
-    {"x", PLY_FLOAT, PLY_FLOAT, offsetof(PlyVertex,x), 0, 0, 0, 0},
-    {"y", PLY_FLOAT, PLY_FLOAT, offsetof(PlyVertex,y), 0, 0, 0, 0},
-    {"z", PLY_FLOAT, PLY_FLOAT, offsetof(PlyVertex,z), 0, 0, 0, 0},
-    {"nx", PLY_FLOAT, PLY_FLOAT, offsetof(PlyVertex,nx), 0, 0, 0, 0},
-    {"ny", PLY_FLOAT, PLY_FLOAT, offsetof(PlyVertex,ny), 0, 0, 0, 0},
-    {"nz", PLY_FLOAT, PLY_FLOAT, offsetof(PlyVertex,nz), 0, 0, 0, 0}
-  };
-
-  // List of property information for a vertex 
-  static PlyProperty face_props[] = { 
-    {"vertex_indices", PLY_INT, PLY_INT, offsetof(PlyFace,verts), 1, PLY_UCHAR, PLY_UCHAR, offsetof(PlyFace,nverts)},
-    {"material_id", PLY_INT, PLY_INT, offsetof(PlyFace,material), 0, 0, 0, 0},
-    {"segment_id", PLY_INT, PLY_INT, offsetof(PlyFace,segment), 0, 0, 0, 0}
-  };
-
-  // Open file 
-  fp = fopen(filename, "rb");
-  if (!fp) {
-    RNFail("Unable to open file: %s", filename);
-    return 0;
-  }
-
-  // Read PLY header
-  ply = ply_read (fp, &nelems, &elist);
-  if (!ply) {
-    RNFail("Unable to read ply file: %s", filename);
-    fclose(fp);
-    return 0;
-  }
-  
-  // Get header info
-  ply_get_info (ply, &version, &file_type);
-
-  // Read all elements
-  for (i = 0; i < nelems; i++) {
-    // Get the description of the element 
-    elem_name = elist[i];
-    plist = ply_get_element_description (ply, elem_name, &num_elems, &nprops);
-
-    // Check element type
-    if (equal_strings ("vertex", elem_name)) {
-      // Allocate block of vertices
-      vertex_block = new R3MeshVertex [num_elems];
-
-      // Resize array of vertices
-      vertices.Resize(num_elems);
-
-      // set up for getting vertex elements 
-      RNBoolean has_normals = 0;
-      for (j = 0; j < nprops; j++) {
-	if (equal_strings("x", plist[j]->name)) ply_get_property (ply, elem_name, &vert_props[0]);
-	else if (equal_strings("y", plist[j]->name)) ply_get_property (ply, elem_name, &vert_props[1]);
-	else if (equal_strings("z", plist[j]->name)) ply_get_property (ply, elem_name, &vert_props[2]);
-	else if (equal_strings("nx", plist[j]->name)) ply_get_property (ply, elem_name, &vert_props[3]); 
-	else if (equal_strings("ny", plist[j]->name)) ply_get_property (ply, elem_name, &vert_props[4]); 
-	else if (equal_strings("nz", plist[j]->name)) ply_get_property (ply, elem_name, &vert_props[5]);
-	if (equal_strings("nx", plist[j]->name)) has_normals = 1;
-      }
-
-      // grab all the vertex elements 
-      for (j = 0; j < num_elems; j++) {
-        // Read vertex into local struct
-        PlyVertex plyvertex;
-        ply_get_element(ply, (void *) &plyvertex);
-
-        // Create mesh vertex
-        R3Point position(plyvertex.x, plyvertex.y, plyvertex.z);
-        R3MeshVertex *v = CreateVertex(position, &vertex_block[j]);
-        if (has_normals) {
-          R3Vector normal(plyvertex.nx, plyvertex.ny, plyvertex.nz);
-          SetVertexNormal(v, normal);
-        }
-      }
-    }
-    else if (equal_strings ("face", elem_name)) {
-      // Resize array of faces
-      faces.Resize(num_elems);
-
-      // set up for getting face elements 
-      for (j = 0; j < nprops; j++) {
-	if (equal_strings("vertex_indices", plist[j]->name)) ply_get_property (ply, elem_name, &face_props[0]);
-	else if (equal_strings("material_id", plist[j]->name)) ply_get_property (ply, elem_name, &face_props[1]);
-	else if (equal_strings("segment_id", plist[j]->name)) ply_get_property (ply, elem_name, &face_props[2]);
-      }
-
-      // grab all the face elements 
-      for (j = 0; j < num_elems; j++) {
-        // Read face into local struct
-        PlyFace plyface;
-        plyface.nverts = 0;
-        plyface.verts = NULL;
-        plyface.material = -1;
-        plyface.segment = 0;
-        ply_get_element(ply, (void *) &plyface);
-
-        // Create mesh face(s)
-        R3MeshVertex *v1 = vertices[plyface.verts[0]];
-        for (int k = 2; k < plyface.nverts; k++) {
-          // Get vertices
-          R3MeshVertex *v2 = vertices[plyface.verts[k-1]];
-          R3MeshVertex *v3 = vertices[plyface.verts[k]];
-
-          // Check plyface
-          assert(plyface.verts[0] >= 0);
-          assert(plyface.verts[k-1] >= 0);
-          assert(plyface.verts[k] >= 0);
-          assert(plyface.verts[0] < vertices.NEntries());
-          assert(plyface.verts[k-1] < vertices.NEntries());
-          assert(plyface.verts[k] < vertices.NEntries());
-
-          // Check vertices
-          if ((v1 == v2) || (v2 == v3) || (v1 == v3)) continue;
-
-          // Create face
-          R3MeshFace *f = CreateFace(v1, v2, v3);
-#if 0
-          if (!f) {
-            // Must have been degeneracy (e.g., three faces sharing an edge), create new vertices
-            // Note: these vertices are allocated separately, and so they will not be deleted (memory leak)
-            // R3MeshVertex *v1a = CreateVertex(VertexPosition(v1));
-            // R3MeshVertex *v2a = CreateVertex(VertexPosition(v2));
-            // R3MeshVertex *v3a = CreateVertex(VertexPosition(v3));
-            // f = CreateFace(v1a, v2a, v3a);
-          } 
-#endif
-          // Set material/segment
-          if (f) SetFaceMaterial(f, plyface.material);
-          if (f) SetFaceSegment(f, plyface.segment);
-        }
-
-        // Free face data allocated by ply ??? THIS MESSES UP WHEN OTHER DATA (SEGMENTS) ARE PRESENT ???
-        if (plyface.verts) free(plyface.verts);
-      }
-    }
-    else {
-      ply_get_other_element (ply, elem_name, num_elems);
-    }
-  }
-
-  // Close the file 
-  ply_close (ply);
-
-  // Return number of faces created
-  return faces.NEntries();
-}
 
 
 
@@ -2942,8 +2765,6 @@
   // Write file of appropriate type
   if (!strncmp(extension, ".ray", 4)) 
     return WriteRayFile(filename);
-  else if (!strncmp(extension, ".ply", 4)) 
-    return WritePlyFile(filename);
   else if (!strncmp(extension, ".obj", 4)) 
     return WriteObjFile(filename);
   else if (!strncmp(extension, ".off", 4)) 
@@ -2999,90 +2820,6 @@
 
 
 
-int R3Mesh::
-WritePlyFile(const char *filename)
-{
-  typedef struct PlyVertex {
-    float x, y, z;
-  } PlyVertex;
-
-  typedef struct PlyFace {
-    unsigned char nverts;
-    int *verts;
-    int material;
-    int segment;
-  } PlyFace;
-
-  // Element names
-  char *elem_names[] = { "vertex", "face" };
-
-  // List of property information for a vertex 
-  static PlyProperty vert_props[] = { 
-    {"x", PLY_FLOAT, PLY_FLOAT, offsetof(PlyVertex,x), 0, 0, 0, 0},
-    {"y", PLY_FLOAT, PLY_FLOAT, offsetof(PlyVertex,y), 0, 0, 0, 0},
-    {"z", PLY_FLOAT, PLY_FLOAT, offsetof(PlyVertex,z), 0, 0, 0, 0},
-  };
-
-  // List of property information for a vertex 
-  static PlyProperty face_props[] = { 
-    {"vertex_indices", PLY_INT, PLY_INT, offsetof(PlyFace,verts), 1, PLY_UCHAR, PLY_UCHAR, offsetof(PlyFace,nverts)},
-    {"material_id", PLY_INT, PLY_INT, offsetof(PlyFace,segment), 0, 0, 0, 0},
-    {"segment_id", PLY_INT, PLY_INT, offsetof(PlyFace,segment), 0, 0, 0, 0}
-  };
-
-  // Open ply file
-  float version;
-  PlyFile *ply = ply_open_for_writing((char *) filename, 2, elem_names, PLY_ASCII, &version);
-  if (!ply) return -1;
-
-  // Describe vertex properties
-  ply_element_count(ply, "vertex", NVertices());
-  ply_describe_property(ply, "vertex", &vert_props[0]);
-  ply_describe_property(ply, "vertex", &vert_props[1]);
-  ply_describe_property(ply, "vertex", &vert_props[2]);
-
-  // Describe face properties
-  ply_element_count(ply, "face", NFaces());
-  ply_describe_property(ply, "face", &face_props[0]);
-  ply_describe_property(ply, "face", &face_props[1]);
-  ply_describe_property(ply, "face", &face_props[2]);
-
-  // Complete header
-  ply_header_complete(ply);
-
-  // Write vertices
-  ply_put_element_setup(ply, "vertex");
-  for (int i = 0; i < NVertices(); i++) {
-    R3MeshVertex *v = Vertex(i);
-    const R3Point& p = VertexPosition(v);
-    PlyVertex ply_vertex;
-    ply_vertex.x = p.X();
-    ply_vertex.y = p.Y();
-    ply_vertex.z = p.Z();
-    ply_put_element(ply, (void *) &ply_vertex);
-  }
-
-  // Write faces
-  ply_put_element_setup(ply, "face");
-  for (int i = 0; i < NFaces(); i++) {
-    R3MeshFace *f = Face(i);
-    static int verts[3];
-    static PlyFace ply_face = { 3, verts, 0 };
-    ply_face.verts[0] = VertexID(VertexOnFace(f, 0));
-    ply_face.verts[1] = VertexID(VertexOnFace(f, 1));
-    ply_face.verts[2] = VertexID(VertexOnFace(f, 2));
-    ply_face.material = FaceMaterial(f);
-    ply_face.segment = FaceSegment(f);
-    ply_put_element(ply, (void *) &ply_face);
-  }
-
-  // Close the file 
-  ply_close(ply);
-
-  // Return number of faces written
-  return NFaces();
-}
-
 
 
 int R3Mesh::
@@ -3581,8 +3318,3 @@
   vertex[0] = vertex[1] = vertex[2] = NULL;
   edge[0] = edge[1] = edge[2] = NULL;
 }
-
-
-
-
-
--- a/pkgs/R3Shapes/R3Mesh.h
+++ b/pkgs/R3Shapes/R3Mesh.h
@@ -450,8 +450,6 @@
       // Loads data structure from OFF (.off) file, returns number of faces created (0 is error)
     int ReadRayFile(const char *filename);
       // Loads data structure from ray file (.ray), returns number of faces created (0 is error)
-    int ReadPlyFile(const char *filename);
-      // Loads data structure from ply file (.ply), returns number of faces created (0 is error)
     int ReadCattFile(const char *filename);
       // Loads data structure from a Catt acoustic file (.cat), returns number of faces created (0 is error)
     int ReadIfsFile(const char *filename);
@@ -464,8 +462,6 @@
      // Writes a file, returns number of faces written (0 is error)
     int WriteRayFile(const char *filename);
      // Writes a ray file, returns number of faces written (0 is error)
-    int WritePlyFile(const char *filename);
-     // Writes a PLY file, returns number of faces written (0 is error)
     int WriteObjFile(const char *filename);
      // Writes a Wavefront OBJ file, returns number of faces written (0 is error)
     int WriteOffFile(const char *filename);
@@ -1437,24 +1433,3 @@
   DrawFaces();
 } 
 #endif
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
--- a/pkgs/R3Shapes/Makefile
+++ b/pkgs/R3Shapes/Makefile
@@ -13,8 +13,7 @@
     R3Affine.C R3Xform.C R3Crdsys.C R3Triad.C R4Matrix.C \
     R3Grid.C \
     R3Halfspace.C R3Plane.C R3Span.C R3Ray.C R3Line.C R3Point.C R3Vector.C \
-    R3Base.C \
-    ply.C
+    R3Base.C 
 
 
 #
@@ -22,12 +21,3 @@
 #
 
 include ../../scripts/Makefile.pkgs
-
-
-
-
-
-
-
-
-
