JWS C++ Library
C++ language utility library
|
00001 /* 00002 * This work is licensed under a Creative Commons 00003 * Attribution-Noncommercial-Share Alike 3.0 United States License. 00004 * 00005 * http://creativecommons.org/licenses/by-nc-sa/3.0/us/ 00006 * 00007 * You are free: 00008 * 00009 * to Share - to copy, distribute, display, and perform the work 00010 * to Remix - to make derivative works 00011 * 00012 * Under the following conditions: 00013 * 00014 * Attribution. You must attribute the work in the manner specified by the 00015 * author or licensor (but not in any way that suggests that they endorse you 00016 * or your use of the work). 00017 * 00018 * Noncommercial. You may not use this work for commercial purposes. 00019 * 00020 * Share Alike. If you alter, transform, or build upon this work, you may 00021 * distribute the resulting work only under the same or similar license to 00022 * this one. 00023 * 00024 * For any reuse or distribution, you must make clear to others the license 00025 * terms of this work. The best way to do this is by including this header. 00026 * 00027 * Any of the above conditions can be waived if you get permission from the 00028 * copyright holder. 00029 * 00030 * Apart from the remix rights granted under this license, nothing in this 00031 * license impairs or restricts the author's moral rights. 00032 */ 00033 00034 00046 #ifndef PARAPIPED_H 00047 #define PARAPIPED_H 00048 00049 00050 #include <jwsc++/config.h> 00051 00052 #include <iostream> 00053 #include <vector> 00054 00055 #include <inttypes.h> 00056 00057 #include <jwsc/vector/vector.h> 00058 #include <jwsc/matrix/matrix.h> 00059 00060 #include <jwsc++/base/cloneable.h> 00061 #include <jwsc++/base/readable.h> 00062 #include <jwsc++/base/writeable.h> 00063 #include <jwsc++/base/exception.h> 00064 #include <jwsc++/graphics/transformable.h> 00065 #include <jwsc++/graphics/renderable.h> 00066 #include <jwsc++/graphics/polymesh.h> 00067 #include <jwsc++/graphics/polygon.h> 00068 00069 00070 namespace jwscxx { 00071 namespace graphics { 00072 00073 00079 class Parapiped_f : public jwscxx::base::Cloneable, 00080 public jwscxx::base::Readable, 00081 public jwscxx::base::Writeable, 00082 public Transformable_f, 00083 public Wire_renderable, 00084 public Wire_occlude_renderable, 00085 public Solid_renderable, 00086 public Polymesh_f 00087 { 00088 public: 00089 00091 Parapiped_f 00092 ( 00093 float x1, float y1, float z1, 00094 float x2, float y2, float z2, 00095 float x3, float y3, float z3, 00096 float x4, float y4, float z4 00097 ); 00098 00099 00101 Parapiped_f 00102 ( 00103 const jwsc::Vector_f* p1, 00104 const jwsc::Vector_f* p2, 00105 const jwsc::Vector_f* p3, 00106 const jwsc::Vector_f* p4 00107 ) 00108 throw (jwscxx::base::Arg_error); 00109 00110 00112 Parapiped_f(const Parapiped_f& p); 00113 00114 00116 Parapiped_f(const char* fname) throw (jwscxx::base::Arg_error, 00117 jwscxx::base::IO_error); 00118 00119 00121 Parapiped_f(std::istream& in) throw (jwscxx::base::Arg_error, 00122 jwscxx::base::IO_error); 00123 00124 00126 virtual ~Parapiped_f(); 00127 00128 00130 virtual Parapiped_f& operator= (const Parapiped_f& p); 00131 00132 00134 virtual Parapiped_f* clone() const; 00135 00136 00138 size_t num_faces() const; 00139 00140 00142 const jwsc::Vector_f* get_point(size_t i) const 00143 throw (jwscxx::base::Arg_error); 00144 00145 00147 const jwsc::Vector_f* get_center() const; 00148 00149 00151 const jwscxx::graphics::Polygon_f* get_face(size_t i) const 00152 throw (jwscxx::base::Arg_error); 00153 00154 00156 const std::vector<const jwscxx::graphics::Polygon_f*>& get_faces() 00157 const; 00158 00159 00161 void set_face_id(size_t i, uint32_t id) 00162 throw (jwscxx::base::Arg_error); 00163 00164 00166 virtual void read(std::istream& in) throw (jwscxx::base::IO_error, 00167 jwscxx::base::Arg_error); 00168 00169 00171 virtual void write(std::ostream& out) const 00172 throw (jwscxx::base::IO_error); 00173 00174 00176 virtual void transform(const jwsc::Matrix_f* M) 00177 throw (jwscxx::base::Arg_error); 00178 00179 00181 virtual void wire_render() const; 00182 00183 00188 virtual void wire_occlude_render() const; 00189 00190 00192 virtual void solid_render() const; 00193 00194 00196 virtual void project(); 00197 00198 00200 uint32_t adjacent_face(uint32_t i, uint32_t p) const 00201 throw (jwscxx::base::Arg_error); 00202 00203 00204 protected: 00205 00207 std::vector<jwscxx::graphics::Polygon_f*> faces; 00208 00210 std::vector<jwsc::Vector_f*> points; 00211 00217 jwsc::Vector_f* center; 00218 00225 jwsc::Matrix_u32* adjacency; 00226 }; 00227 00228 00234 class Parapiped_d : public jwscxx::base::Cloneable, 00235 public jwscxx::base::Readable, 00236 public jwscxx::base::Writeable, 00237 public Transformable_d, 00238 public Wire_renderable, 00239 public Wire_occlude_renderable, 00240 public Solid_renderable, 00241 public Polymesh_d 00242 { 00243 public: 00244 00246 Parapiped_d 00247 ( 00248 double x1, double y1, double z1, 00249 double x2, double y2, double z2, 00250 double x3, double y3, double z3, 00251 double x4, double y4, double z4 00252 ); 00253 00254 00256 Parapiped_d 00257 ( 00258 const jwsc::Vector_d* p1, 00259 const jwsc::Vector_d* p2, 00260 const jwsc::Vector_d* p3, 00261 const jwsc::Vector_d* p4 00262 ) 00263 throw (jwscxx::base::Arg_error); 00264 00265 00267 Parapiped_d(const Parapiped_d& p); 00268 00269 00271 Parapiped_d(const char* fname) throw (jwscxx::base::Arg_error, 00272 jwscxx::base::IO_error); 00273 00274 00276 Parapiped_d(std::istream& in) throw (jwscxx::base::Arg_error, 00277 jwscxx::base::IO_error); 00278 00279 00281 virtual ~Parapiped_d(); 00282 00283 00285 virtual Parapiped_d& operator= (const Parapiped_d& p); 00286 00287 00289 virtual Parapiped_d* clone() const; 00290 00291 00293 size_t num_faces() const; 00294 00295 00297 const jwsc::Vector_d* get_point(size_t i) const 00298 throw (jwscxx::base::Arg_error); 00299 00300 00302 const jwsc::Vector_d* get_center() const; 00303 00304 00306 const jwscxx::graphics::Polygon_d* get_face(size_t i) const 00307 throw (jwscxx::base::Arg_error); 00308 00309 00311 const std::vector<const jwscxx::graphics::Polygon_d*>& get_faces() 00312 const; 00313 00314 00316 void set_face_id(size_t i, uint32_t id) 00317 throw (jwscxx::base::Arg_error); 00318 00319 00321 virtual void read(std::istream& in) throw (jwscxx::base::IO_error, 00322 jwscxx::base::Arg_error); 00323 00324 00326 virtual void write(std::ostream& out) const 00327 throw (jwscxx::base::IO_error); 00328 00329 00331 virtual void transform(const jwsc::Matrix_d* M) 00332 throw (jwscxx::base::Arg_error); 00333 00334 00336 virtual void wire_render() const; 00337 00338 00343 virtual void wire_occlude_render() const; 00344 00345 00347 virtual void solid_render() const; 00348 00349 00351 virtual void project(); 00352 00353 00355 uint32_t adjacent_face(uint32_t i, uint32_t p) const 00356 throw (jwscxx::base::Arg_error); 00357 00358 00359 protected: 00360 00362 std::vector<jwscxx::graphics::Polygon_d*> faces; 00363 00365 std::vector<jwsc::Vector_d*> points; 00366 00372 jwsc::Vector_d* center; 00373 00380 jwsc::Matrix_u32* adjacency; 00381 }; 00382 00383 00384 }} 00385 00386 00387 #endif