Text archives Help
- From: thiago@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r330 - in trunk/Model: Primitives Readers Readers/rply Textures
- Date: Tue, 17 May 2005 01:15:39 -0600 (MDT)
Author: thiago
Date: Tue May 17 01:15:38 2005
New Revision: 330
Added:
trunk/Model/Primitives/VertexColoredTriangle.cc
trunk/Model/Primitives/VertexColoredTriangle.h
trunk/Model/Textures/TriVerTexture.cc
trunk/Model/Textures/TriVerTexture.h
Modified:
trunk/Model/Primitives/CMakeLists.txt
trunk/Model/Primitives/sub.mk
trunk/Model/Readers/PlyReader.cc
trunk/Model/Readers/rply/rply.h
Log:
can now read in ply files with diffuse color. Adding support for other ply
color formats is trivial. Try it out with
/usr/sci/data/Geometry/Stanford_Sculptures/test_colored.ply. Needed to add
special triangle and texture classes since color is located at Vertices and
not face.
Modified: trunk/Model/Primitives/CMakeLists.txt
==============================================================================
--- trunk/Model/Primitives/CMakeLists.txt (original)
+++ trunk/Model/Primitives/CMakeLists.txt Tue May 17 01:15:38 2005
@@ -9,6 +9,7 @@
Primitives/Triangle.cc
Primitives/HeavyTriangle.cc
Primitives/TexTriangle.cc
+ Primitives/VertexColoredTriangle.cc
Primitives/Disk.cc
Primitives/Hemisphere.cc
Primitives/Heightfield.cc
Added: trunk/Model/Primitives/VertexColoredTriangle.cc
==============================================================================
--- (empty file)
+++ trunk/Model/Primitives/VertexColoredTriangle.cc Tue May 17 01:15:38
2005
@@ -0,0 +1,31 @@
+#include <Model/Primitives/VertexColoredTriangle.h>
+
+namespace Manta {
+
+ VertexColoredTriangle::VertexColoredTriangle(
+ Material* mat,
+ const Point& _p1,
+ const Point& _p2,
+ const Point& _p3,
+ const Color& _color1,
+ const Color& _color2,
+ const Color& _color3)
+ : Triangle(mat, _p1,_p2,_p3)
+ {
+ colors[0] = _color1;
+ colors[1] = _color2;
+ colors[2] = _color3;
+ }
+
+ VertexColoredTriangle::~VertexColoredTriangle()
+ {
+ }
+
+ Color& VertexColoredTriangle::getVertexColor(int which) {
+ return colors[which];
+ }
+
+ const Color& VertexColoredTriangle::getVertexColor(int which) const {
+ return colors[which];
+ }
+}
Added: trunk/Model/Primitives/VertexColoredTriangle.h
==============================================================================
--- (empty file)
+++ trunk/Model/Primitives/VertexColoredTriangle.h Tue May 17 01:15:38
2005
@@ -0,0 +1,29 @@
+
+#ifndef Manta_Model_VertexColoredTriangle_h
+#define Manta_Model_VertexColoredTriangle_h
+
+#include <Model/Primitives/Triangle.h>
+#include <Core/Color/Color.h>
+
+namespace Manta
+{
+ class VertexColoredTriangle : public Triangle {
+ public:
+ VertexColoredTriangle(Material* mat,
+ const Point& _p1,
+ const Point& _p2,
+ const Point& _p3,
+ const Color& _color1,
+ const Color& _color2,
+ const Color& _color3);
+ virtual ~VertexColoredTriangle();
+
+ Color& getVertexColor(int which);
+ const Color& getVertexColor(int which) const;
+
+ protected:
+ Color colors[3];
+ };
+}
+
+#endif
Modified: trunk/Model/Primitives/sub.mk
==============================================================================
--- trunk/Model/Primitives/sub.mk (original)
+++ trunk/Model/Primitives/sub.mk Tue May 17 01:15:38 2005
@@ -14,6 +14,7 @@
$(SRCDIR)/Sphere.cc \
$(SRCDIR)/SuperEllipsoid.cc \
$(SRCDIR)/Triangle.cc \
+ $(SRCDIR)/VertexColoredTriangle.cc \
$(SRCDIR)/Ring.cc \
$(SRCDIR)/Cylinder.cc \
$(SRCDIR)/Cube.cc \
Modified: trunk/Model/Readers/PlyReader.cc
==============================================================================
--- trunk/Model/Readers/PlyReader.cc (original)
+++ trunk/Model/Readers/PlyReader.cc Tue May 17 01:15:38 2005
@@ -1,40 +1,41 @@
#include <Model/Primitives/Triangle.h>
+#include <Model/Primitives/VertexColoredTriangle.h>
+#include <Model/Textures/TriVerTexture.h>
#include <Model/Readers/PlyReader.h>
#include <Model/Materials/Lambertian.h>
+#include <Core/Color/Color.h>
+#include <Core/Color/RGBColor.h>
#include <SCIRun/Core/Exceptions/FileNotFound.h>
#include <sstream>
#include <stdlib.h>
-
#include "rply/rply.h"
-//TODO: colors, normals?, acceleration structure.
+//TODO: normals?, acceleration structure.
-//eek! all these using namespaces might cause ugly conflicts!!
using namespace Manta;
-using namespace std;
-Material *defaultMaterial;
+Material *defaultMaterial = NULL;
+
+double maxColorValue;
+
+bool coloredTriangleMode = false;
struct VertexData {
- double x, y, z;
- double r, g, b;
+ Point point;
+ RGBColor color;
};
-std::vector<Point> vertices;
+std::vector<VertexData> vertices;
VertexData vertexData;
AffineTransform *t;
-static int addPoint() {
- //TODO: check if we used color and if so, add it to color array
-
- Point p(vertexData.x, vertexData.y, vertexData.z);
- vertices.push_back(*t*p);
+static void addVertex() {
+ vertexData.point = *t * vertexData.point;
+ vertices.push_back(vertexData);
}
static int vertex_cb(p_ply_argument argument) {
- void* ptr_userdata;
-
ply_get_argument_user_data(argument, NULL, NULL);
const char* name;
@@ -42,26 +43,25 @@
ply_get_argument_property(argument, &property, NULL, NULL);
ply_get_property_info(property, &name, NULL, NULL, NULL);
-
long vertexIndex;
ply_get_argument_element(argument, NULL, &vertexIndex);
if (vertexIndex == vertices.size()+1) {
- addPoint();
+ addVertex();
}
if (strcmp(name, "x") == 0)
- vertexData.x = ply_get_argument_value(argument);
+ vertexData.point[0] = ply_get_argument_value(argument);
else if (strcmp(name, "y") == 0)
- vertexData.y = ply_get_argument_value(argument);
+ vertexData.point[1] = ply_get_argument_value(argument);
else if (strcmp(name, "z") == 0)
- vertexData.z = ply_get_argument_value(argument);
+ vertexData.point[2] = ply_get_argument_value(argument);
else if (strcmp(name, "diffuse_red") == 0)
- vertexData.r = ply_get_argument_value(argument);
+ vertexData.color.setR(ply_get_argument_value(argument) /
maxColorValue);
else if (strcmp(name, "diffuse_green") == 0)
- vertexData.g = ply_get_argument_value(argument);
+ vertexData.color.setG(ply_get_argument_value(argument) /
maxColorValue);
else if (strcmp(name, "diffuse_blue") == 0)
- vertexData.b = ply_get_argument_value(argument);
+ vertexData.color.setB(ply_get_argument_value(argument) /
maxColorValue);
return 1;
}
@@ -77,14 +77,15 @@
long polyIndex, polyVertex;
ply_get_argument_element(argument, NULL, &polyIndex);
- if (polyIndex == 0) {
- addPoint();
+ ply_get_argument_property(argument, NULL, &length, &polyVertex);
+
+ //do this once only to add last vertex.
+ if (polyIndex == 0 && polyVertex == -1) {
+ addVertex();
}
- ply_get_argument_property(argument, NULL, &length, &polyVertex);
currVertexIndex = static_cast<int>(ply_get_argument_value(argument));
- //TODO: assign material from ply file if it exists to mat
Material *mat = defaultMaterial;
switch (polyVertex)
@@ -95,7 +96,19 @@
case 1: prevVertexIndex = currVertexIndex;
break;
default:
- group->add(new Triangle(mat, vertices[firstVertexIndex],
vertices[prevVertexIndex], vertices[currVertexIndex]));
+ if (coloredTriangleMode)
+ group->add(new VertexColoredTriangle(mat,
+ vertices[firstVertexIndex].point,
+ vertices[prevVertexIndex].point,
+ vertices[currVertexIndex].point,
+
Color(vertices[firstVertexIndex].color),
+ Color(vertices[prevVertexIndex].color),
+
Color(vertices[currVertexIndex].color)));
+ else
+ group->add(new Triangle(mat, vertices[firstVertexIndex].point,
+ vertices[prevVertexIndex].point,
+ vertices[currVertexIndex].point));
+
prevVertexIndex = currVertexIndex;
break;
}
@@ -107,7 +120,6 @@
bool
Manta::readPlyFile(const string fileName, AffineTransform &_t,
Group *g, int gridsize, Material *m) {
- long nFaces;
long nVertices;
int originalSize = g->getNumObjs();
@@ -123,11 +135,6 @@
if (!ply_read_header(ply)) return false;
-
- if (m)
- defaultMaterial = m;
- else
- defaultMaterial = new Lambertian(Color(RGBColor(1,1,1)));
nVertices = ply_set_read_cb(ply, "vertex", "x", vertex_cb,
NULL, 0);
@@ -139,19 +146,63 @@
ply_set_read_cb(ply, "vertex", "z", vertex_cb,
NULL, 0);
+ //get vertex color property
+ p_ply_property property;
+
+ //try and get diffuse RGB color property
+ property = ply_find_property(ply_find_element(ply, "vertex"),
"diffuse_red");
+
ply_set_read_cb(ply, "vertex", "diffuse_red", vertex_cb,
NULL, 0);
ply_set_read_cb(ply, "vertex", "diffuse_blue", vertex_cb,
NULL, 0);
ply_set_read_cb(ply, "vertex", "diffuse_green", vertex_cb,
NULL, 0);
-
- nFaces = ply_set_read_cb(ply, "face", "vertex_indices", face_cb, g, 0);
+
+
+ /*if we add other color types, need to try getting their property
+ *if current property is still NULL.
+ */
+
+ if (property)
+ {
+ //TODO: we might not want to overwrite the matl passed in to us...
+ defaultMaterial = new Lambertian(new TriVerTexture());
+ coloredTriangleMode = true;
+ e_ply_type type;
+ ply_get_property_info(property, NULL, &type, NULL, NULL);
+ if (type)
+ {
+ switch(type)
+ {
+ //TODO: handle all the other types.
+ case PLY_CHAR: maxColorValue=255;
+ break;
+ case PLY_UCHAR: maxColorValue=511;
+ break;
+ case PLY_DOUBLE:
+ case PLY_FLOAT: maxColorValue=1;
+ break;
+ default: maxColorValue=1; //shouldn't get here. Need to
+ //add case for this new type
+ break;
+ }
+ }
+ }
+
+ ply_set_read_cb(ply, "face", "vertex_indices", face_cb, g, 0);
+
+ if (defaultMaterial)
+ { } //do nothing
+ else if (m)
+ defaultMaterial = m;
+ else
+ defaultMaterial = new Lambertian(Color(RGBColor(1,1,1)));
if (!ply_read(ply)) {
//need to clean up group.
g->shrinkTo(originalSize, true);
- if (!m)
+ if (!m && defaultMaterial)
delete defaultMaterial;
return false;
Modified: trunk/Model/Readers/rply/rply.h
==============================================================================
--- trunk/Model/Readers/rply/rply.h (original)
+++ trunk/Model/Readers/rply/rply.h Tue May 17 01:15:38 2005
@@ -227,66 +227,6 @@
int ply_get_property_info(p_ply_property property, const char** name,
e_ply_type *type, e_ply_type *length_type, e_ply_type *value_type);
-/* /\*
---------------------------------------------------------------------- */
-/* * Creates new ply file */
-/* * */
-/* * name: file name */
-/* * storage_mode: file format mode */
-/* * */
-/* * Returns handle to ply file if successfull, NULL otherwise */
-/* * ----------------------------------------------------------------------
*\/ */
-/* p_ply ply_create(const char *name, e_ply_storage_mode storage_mode, */
-/* p_ply_error_cb error_cb); */
-
-/* /\*
---------------------------------------------------------------------- */
-/* * Adds a new element to the ply file created by ply_create */
-/* * */
-/* * ply: handle returned by ply_create */
-/* * name: name of new element */
-/* * ninstances: number of element of this time in file */
-/* * */
-/* * Returns 1 if successfull, 0 otherwise */
-/* * ----------------------------------------------------------------------
*\/ */
-/* int ply_add_element(p_ply ply, const char *name, long ninstances); */
-
-/* /\*
---------------------------------------------------------------------- */
-/* * Adds a new property to the last element added by ply_add_element */
-/* * */
-/* * ply: handle returned by ply_create */
-/* * name: name of new property */
-/* * type: property type */
-/* * length_type: scalar type of length field of a list property */
-/* * value_type: scalar type of value fields of a list property */
-/* * */
-/* * Returns 1 if successfull, 0 otherwise */
-/* * ----------------------------------------------------------------------
*\/ */
-/* int ply_add_property(p_ply ply, const char *name, e_ply_type type, */
-/* e_ply_type length_type, e_ply_type value_type); */
-
-/* /\*
---------------------------------------------------------------------- */
-/* * Adds a new list property to the last element added by ply_add_element
*/
-/* * */
-/* * ply: handle returned by ply_create */
-/* * name: name of new property */
-/* * length_type: scalar type of length field of a list property */
-/* * value_type: scalar type of value fields of a list property */
-/* * */
-/* * Returns 1 if successfull, 0 otherwise */
-/* * ----------------------------------------------------------------------
*\/ */
-/* int ply_add_list_property(p_ply ply, const char *name, */
-/* e_ply_type length_type, e_ply_type value_type); */
-
-/* /\*
---------------------------------------------------------------------- */
-/* * Adds a new property to the last element added by ply_add_element */
-/* * */
-/* * ply: handle returned by ply_create */
-/* * name: name of new property */
-/* * type: property type */
-/* * */
-/* * Returns 1 if successfull, 0 otherwise */
-/* * ----------------------------------------------------------------------
*\/ */
-/* int ply_add_scalar_property(p_ply ply, const char *name, e_ply_type
type); */
-
/* ----------------------------------------------------------------------
* Adds a new comment item
*
Added: trunk/Model/Textures/TriVerTexture.cc
==============================================================================
--- (empty file)
+++ trunk/Model/Textures/TriVerTexture.cc Tue May 17 01:15:38 2005
@@ -0,0 +1,31 @@
+
+#include <Model/Textures/TriVerTexture.h>
+#include <Interface/RayPacket.h>
+#include <Model/Primitives/VertexColoredTriangle.h>
+
+namespace Manta {
+ TriVerTexture::TriVerTexture()
+ {
+ }
+
+ TriVerTexture::~TriVerTexture()
+ {
+ }
+
+ void TriVerTexture::mapValues(const RenderContext& context,
+ RayPacket& rays,
+ Color results[]) const
+ {
+ rays.computeTextureCoordinates3( context );
+
+ for( int i = 0; i < rays.getSize(); i++ ) {
+ RayPacket::Element &e = rays.get( i );
+ Point T = e.texCoords;
+ Triangle::TriangleHit& th =
e.hitInfo.scratchpad<Triangle::TriangleHit>();
+ const VertexColoredTriangle* vct =
+ static_cast<const VertexColoredTriangle*>(e.hitInfo.hitPrimitive());
+ results[i] = vct->getVertexColor(0)*(1 - th.a - th.b) +
+ vct->getVertexColor(1)*th.a + vct->getVertexColor(2)*th.b;
+ }
+ }
+}
Added: trunk/Model/Textures/TriVerTexture.h
==============================================================================
--- (empty file)
+++ trunk/Model/Textures/TriVerTexture.h Tue May 17 01:15:38 2005
@@ -0,0 +1,31 @@
+#ifndef Manta_Model_TriVerTexture_h
+#define Manta_Model_TriVerTexture_h
+
+#include <Interface/Texture.h>
+
+
+//TriVerTexture returns a color interpolated from three vertices.
+
+namespace Manta {
+ class RayPacket;
+ class RenderContext;
+ class TriVerTexture : public Texture<Color> {
+ public:
+ TriVerTexture();
+ virtual ~TriVerTexture();
+
+ virtual void mapValues(const RenderContext& context, RayPacket& rays,
+ Color results[]) const;
+
+ private:
+ TriVerTexture(const TriVerTexture&);
+ TriVerTexture& operator=(const TriVerTexture&);
+ };
+}
+
+#ifdef __GNUG__
+// This should instead be a configure variable...
+#include <Model/Textures/TriVerTexture.cc>
+#endif
+
+#endif
- [MANTA] r330 - in trunk/Model: Primitives Readers Readers/rply Textures, thiago, 05/17/2005
Archive powered by MHonArc 2.6.16.