Subversion Repositories gelsvn

Rev

Rev 404 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 404 Rev 595
Line 1... Line -...
1
/*
-
 
-
 
1
/* ----------------------------------------------------------------------- *
2
 *  ply_load.cpp
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
3
 *  GEL
-
 
4
 *
-
 
5
 *  Created by J. Andreas Bærentzen on 08/08/07.
3
 * Copyright (C) the authors and DTU Informatics
6
 *  Copyright 2007 __MyCompanyName__. All rights reserved.
4
 * For license and list of authors, see ../../doc/intro.pdf
7
 *
-
 
8
 */
-
 
9
 
-
 
-
 
5
 * ----------------------------------------------------------------------- */
10
 
6
 
11
#include <stdio.h>
7
#include <stdio.h>
12
#include <math.h>
8
#include <math.h>
13
#include <string.h>
9
#include <string.h>
14
#include "rply.h"
10
#include "rply.h"
15
#include "ply_load.h"
11
#include "ply_load.h"
16
#include <CGLA/Vec4f.h>
12
#include <CGLA/Vec4f.h>
17
 
13
 
-
 
14
namespace Geometry
-
 
15
{
18
using namespace std;
16
    using namespace std;
19
using namespace Geometry;
-
 
20
using namespace CGLA;
17
    using namespace CGLA;
21
 
18
 
22
namespace 
19
    namespace 
23
{
20
    {
24
	
-
 
25
	TriMesh *mesh;
21
        TriMesh *mesh;
26
	
22
 
27
	int vertex_cb(p_ply_argument argument) {
23
        int vertex_cb(p_ply_argument argument) {
28
		static int idx=0;
24
            static int idx=0;
29
		static Vec3f p;
25
            static Vec3f p;
30
		long eol;
26
            int eol;
31
		ply_get_argument_user_data(argument, NULL, &eol);
27
            ply_get_argument_user_data(argument, NULL, &eol);
32
		if(idx<3)
28
            if(idx<3)
33
			p[idx] = ply_get_argument_value(argument);
29
                p[idx] = ply_get_argument_value(argument);
34
		++idx;
30
            ++idx;
35
		if (eol) 
31
            if (eol) 
Line 40... Line 36...
40
		return 1;
36
            return 1;
41
	}
37
        }
42
	
38
 
43
	int face_cb(p_ply_argument argument) {
39
        int face_cb(p_ply_argument argument) {
44
		static Vec3i f;
40
            static Vec3i f;
45
		long length, value_index;
41
            int length, value_index;
46
		ply_get_argument_property(argument, NULL, &length, &value_index);
42
            ply_get_argument_property(argument, NULL, &length, &value_index);
47
		if(value_index >= 0)
43
            if(value_index >= 0)
48
		{
44
            {
49
			if(value_index < 2)
45
                if(value_index < 2)
50
				f[value_index] = ply_get_argument_value(argument);	
46
                    f[value_index] = ply_get_argument_value(argument);	
Line 58... Line 54...
58
		}
54
            }
59
		return 1;
55
            return 1;
60
	}
56
        }
61
}
57
    }
62
 
58
 
63
namespace Geometry
-
 
64
{
-
 
65
	void ply_load(const std::string& fn, Geometry::TriMesh& _mesh)
59
    bool ply_load(const std::string& fn, Geometry::TriMesh& _mesh)
66
	{
60
    {
67
		mesh = &_mesh;
61
        mesh = &_mesh;
68
		
62
 
69
		_mesh.materials.resize(1);
63
        _mesh.materials.resize(1);
70
		_mesh.materials[0].diffuse[0] = 172.0f/256.0f; 
64
        _mesh.materials[0].diffuse[0] = 172.0f/256.0f; 
Line 73... Line 67...
73
		_mesh.materials[0].specular[0] = 0.6f; 
67
        _mesh.materials[0].specular[0] = 0.6f; 
74
		_mesh.materials[0].specular[1] = 0.6f;
68
        _mesh.materials[0].specular[1] = 0.6f;
75
		_mesh.materials[0].specular[2] = 0.6f;
69
        _mesh.materials[0].specular[2] = 0.6f;
76
		_mesh.materials[0].shininess = 128.0f;
70
        _mesh.materials[0].shininess = 128.0f;
77
		
71
 
78
		long nvertices, ntriangles;
-
 
79
		p_ply ply = ply_open(fn.c_str(), NULL);
72
        p_ply ply = ply_open(fn.c_str(), NULL);
80
		if (!ply) return;
73
        if (!ply) return false;
81
		if (!ply_read_header(ply)) return;
74
        if (!ply_read_header(ply)) return false;
82
		nvertices = ply_set_read_cb(ply, "vertex", "x", vertex_cb, NULL, 0);
75
        ply_set_read_cb(ply, "vertex", "x", vertex_cb, NULL, 0);
83
		ply_set_read_cb(ply, "vertex", "y", vertex_cb, NULL, 0);
76
        ply_set_read_cb(ply, "vertex", "y", vertex_cb, NULL, 0);
84
		ply_set_read_cb(ply, "vertex", "z", vertex_cb, NULL, 1);
77
        ply_set_read_cb(ply, "vertex", "z", vertex_cb, NULL, 1);
85
		ntriangles = ply_set_read_cb(ply, "face", "vertex_indices", face_cb, NULL, 0);
78
        ply_set_read_cb(ply, "face", "vertex_indices", face_cb, NULL, 0);
86
		ply_read(ply);
79
        ply_read(ply);
87
		ply_close(ply);
80
        ply_close(ply);
-
 
81
        return true;
88
	}
82
    }
89
}
83
}
90
 
84