exportPov.h 5.48 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
4
#ifndef EXPORT_POV_H
#define EXPORT_POV

#include "Topology/generic/attributeHandler.h"
5
#include "Utils/cgognStream.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
6
7
8
9
10
11
12
13
14
15
16
17
18

namespace CGoGN
{

namespace Algo
{

namespace ExportPov
{

template <typename PFP>
void exportTriangleWire(std::ofstream& out,typename PFP::VEC3& p1,typename PFP::VEC3& p2,typename PFP::VEC3& p3)
{
Thomas's avatar
Thomas committed
19
		out << "cylinder { <" << p1[0] << "," << p1[2] << "," << p1[1] << ">, <" << p2[0] << "," << p2[2] << "," << p2[1] << ">, 0.5 }" << std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
20

Thomas's avatar
Thomas committed
21
		out << "cylinder { <" << p1[0] << "," << p1[2] << "," << p1[1] << ">, <" << p3[0] << "," << p3[2] << "," << p3[1] << ">, 0.5 }" << std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
22

Thomas's avatar
Thomas committed
23
		out << "cylinder { <" << p3[0] << "," << p3[2] << "," << p3[1] << ">, <" << p2[0] << "," << p2[2] << "," << p2[1] << ">, 0.5 }" << std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
24
25
26
27
28
}

template <typename PFP>
void exportTrianglePlain(std::ofstream& out,typename PFP::VEC3& p1,typename PFP::VEC3& p2,typename PFP::VEC3& p3)
{
Thomas's avatar
Thomas committed
29
30
31
32
33
		out << "triangle {" << std::endl;
		out << "<" << p1[0] << "," << p1[2] << "," << p1[1] << ">," << std::endl;
		out << "<" << p2[0] << "," << p2[2] << "," << p2[1] << ">, " << std::endl;
		out << "<" << p3[0] << "," << p3[2] << "," << p3[1] << "> " << std::endl;
		out << "}" << std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
34
35
36
37
38
}

template <typename PFP>
void exportMeshPlain(std::ofstream& out, typename PFP::MAP& map, typename PFP::TVEC3& position, const std::string& meshName, const FunctorSelect& good = SelectorTrue())
{
Thomas's avatar
Thomas committed
39
	out << "#declare " << meshName << "= union {" << std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
40
41
42
43
44
45
46
47

	DartMarkerStore traite(map);

	for(Dart d = map.begin() ; d!= map.end() ; map.next(d)) {
		if(good(d) && !traite.isMarked(d)) {
			unsigned int nb=0;
			Dart dd=d;
			do {
48
				traite.markOrbit(DART,dd);
Pierre Kraemer's avatar
Pierre Kraemer committed
49
50
51
52
53
54
55
56
				dd = map.phi1(dd);
				nb++;
			} while(dd!=d);

			if(nb==3) {
				Algo::ExportPov::exportTrianglePlain<PFP>(out,position[dd],position[map.phi1(dd)],position[map.phi1(map.phi1(dd))]);
			}
			else {
Thomas's avatar
Thomas committed
57
					out << "polygon{ " << nb+1 << std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
58
59
					dd=d;
					do {
Thomas's avatar
Thomas committed
60
						out << "<" << position[dd][0] << "," << position[dd][2] << "," << position[dd][1] << ">," << std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
61
62
						dd = map.phi1(dd);
					}while(dd!=d);
Thomas's avatar
Thomas committed
63
64
					out << "<" << position[d][0] << "," << position[d][2] << "," << position[d][1] << ">" << std::endl;
					out << "}" << std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
65
66
67
68
			}
		}
	}

Thomas's avatar
Thomas committed
69
	out << "}" << std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
70
71
72
73
74
}

template <typename PFP>
void exportMeshWire(std::ofstream& out, typename PFP::MAP& map, typename PFP::TVEC3& position, const std::string& meshName, const FunctorSelect& good = SelectorTrue())
{
Thomas's avatar
Thomas committed
75
	out << "#declare " << meshName << "= union {" << std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
76
77
78
79
80
81
82
83

	DartMarkerStore traite(map);

	for(Dart d = map.begin() ; d!= map.end() ; map.next(d)) {
		if(good(d) && !traite.isMarked(d)) {
			unsigned int nb=0;
			Dart dd=d;
			do {
84
				traite.markOrbit(DART,dd);
Pierre Kraemer's avatar
Pierre Kraemer committed
85
86
87
88
89
90
91
92
93
94
95
				dd = map.phi1(dd);
				nb++;
			} while(dd!=d);

			if(nb==3) {
				Algo::ExportPov::exportTriangleWire<PFP>(out,position[dd],position[map.phi1(dd)],position[map.phi1(map.phi1(dd))]);
			}
			else {
					dd=d;
					do {
						if(position[dd][0]!=position[map.phi1(dd)][0] || position[dd][1]!=position[map.phi1(dd)][1] || position[dd][2]!=position[map.phi1(dd)][2]) {
Thomas's avatar
Thomas committed
96
97
98
99
							out << "cylinder{ " << std::endl;
							out << "<" << position[dd][0] << "," << position[dd][2] << "," << position[dd][1] << ">," << std::endl;
							out << "<" << position[map.phi1(dd)][0] << "," << position[map.phi1(dd)][2] << "," << position[map.phi1(dd)][1] << ">, 0.5" << std::endl;
							out << "}" << std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
100
101
102
103
104
105
106
						}
						dd = map.phi1(dd);
					}while(dd!=d);
			}
		}
	}

Thomas's avatar
Thomas committed
107
	out << "}" << std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
108
109
110
111
112
113
114
}

template <typename PFP>
bool exportScenePov(typename PFP::MAP& map, typename PFP::TVEC3& position, const std::string& filename, typename PFP::VEC3 cameraPos, typename PFP::VEC3 cameraLook, typename PFP::VEC3 translate, float angle_X, float angle_Y, float angle_Z,const FunctorSelect& good = SelectorTrue())
{
	std::ofstream out(filename.c_str(), std::ios::out);
	if (!out.good()) {
115
		CGoGNerr << "(export) Unable to open file " << filename << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
116
117
118
119
120
121
122
123
		return false;
	}

	float angleX = angle_X;
	float angleY = angle_Y;
	float angleZ = angle_Z;

	//define the camera position
Thomas's avatar
Thomas committed
124
	out << "camera { location <" << cameraPos[0] << "," << cameraPos[1] << "," << cameraPos[2] << "> look_at <" << cameraLook[0] << "," << cameraLook[1] << "," << cameraLook[2] <<">}" << std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
125
	//set a "infinite" plane 
Thomas's avatar
Thomas committed
126
// 	out << "plane { y, -1 pigment { color rgb 1 } }" << std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
127
	//set a sky sphere
Thomas's avatar
Thomas committed
128
129
	out << "sphere { <0, 0, 0>, 5000";
	out << "texture{ pigment { color rgb <1, 1, 1>}	finish { ambient 1 diffuse 0 } } }" << std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
130
	//put some lights
Thomas's avatar
Thomas committed
131
132
	out << "light_source { <" << cameraPos[0] << "," << cameraPos[1] << "," << cameraPos[2] << "> color rgb 0.45}" << std::endl;
// 	out << "light_source { <-120, -300, -10> color rgb 0.25 }"<< std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
133
	//set a high quality rendering
Thomas's avatar
Thomas committed
134
135
136
137
	out << "global_settings {" << std::endl;
	out << "radiosity {" << std::endl;
	out << "pretrace_start 0.08 pretrace_end 0.04" << std::endl;
	out << "count 100 nearest_count 10 error_bound 0.15 recursion_limit 1 low_error_factor 0.2 gray_threshold 0.0 minimum_reuse 0.015 brightness 1 adc_bailout 0.01/2 normal off media off} max_trace_level 255}" << std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
138
139
140

	Algo::ExportPov::exportMeshPlain<PFP>(out,map,position,"myMesh",good);

Thomas's avatar
Thomas committed
141
142
143
144
	out << "object {myMesh" << std::endl;
 	out << "translate <" << translate[0] << "," << translate[1] << "," << translate[2] << ">" << std::endl;
 	out << "rotate <" << angleX << "," << angleY << "," << angleZ << "> " << std::endl;
 	out << "texture{ pigment{ color rgb<1.0,1.0,1>} finish { ambient rgb 0.05 brilliance 0.5 } } }" << std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
145
146
147
148
149
150
151
152
153
154
155

	out.close();
	return true;
}

}

}

}

untereiner's avatar
untereiner committed
156
#endif