#include <marchingcubes.h>
Collaboration diagram for EMAN::U3DWriter:
Public Types | |
typedef unsigned int | U32 |
typedef long unsigned int | U64 |
typedef double | F64 |
typedef float | F32 |
typedef short int | I16 |
typedef short unsigned int | U16 |
typedef unsigned char | U8 |
Public Member Functions | |
U3DWriter () | |
~U3DWriter () | |
int | write (const string &filename) |
ostream & | write (ostream &) |
template<> | |
ostream & | write (ostream &os, const string &s) |
Private Member Functions | |
unsigned int | size_of_in_bytes () |
void | test_type_sizes () |
ostream & | write_header (ostream &) |
ostream & | write_clod_mesh_generator_node (ostream &os) |
template<typename type> | |
ostream & | write (ostream &os, const type &T) |
Private Attributes | |
U32 | DIFFUSE_COLOR_COUNT |
U32 | SPECULAR_COLOR_COUNT |
CustomVector< F32 > | pp |
CustomVector< F32 > | nn |
CustomVector< unsigned int > | ff |
Definition at line 364 of file marchingcubes.h.
typedef float EMAN::U3DWriter::F32 |
Definition at line 369 of file marchingcubes.h.
typedef double EMAN::U3DWriter::F64 |
Definition at line 368 of file marchingcubes.h.
typedef short int EMAN::U3DWriter::I16 |
Definition at line 370 of file marchingcubes.h.
typedef short unsigned int EMAN::U3DWriter::U16 |
Definition at line 371 of file marchingcubes.h.
typedef unsigned int EMAN::U3DWriter::U32 |
Definition at line 366 of file marchingcubes.h.
typedef long unsigned int EMAN::U3DWriter::U64 |
Definition at line 367 of file marchingcubes.h.
typedef unsigned char EMAN::U3DWriter::U8 |
Definition at line 372 of file marchingcubes.h.
U3DWriter::U3DWriter | ( | ) |
Definition at line 837 of file marchingcubes.cpp.
00837 : DIFFUSE_COLOR_COUNT(1), 00838 SPECULAR_COLOR_COUNT(1) 00839 { 00840 }
U3DWriter::~U3DWriter | ( | ) |
unsigned int U3DWriter::size_of_in_bytes | ( | ) | [private] |
Definition at line 859 of file marchingcubes.cpp.
Referenced by write_header().
00859 { 00860 // this is just the size in bytes of all of the entries in this object that are written to the binary 00861 // output. This is based only on the behavior of write_header and needs to be udpated 00862 unsigned size = 4+2+2+4+4+8+4+8; // 36 bytes 00863 return size; 00864 }
void U3DWriter::test_type_sizes | ( | ) | [private] |
Definition at line 897 of file marchingcubes.cpp.
Referenced by write(), and write_header().
00898 { 00899 bool error = false; 00900 if (sizeof(F64) != 8 ){ 00901 cout << "Error, size of double is not 64 bytes, it's " << sizeof(F64)*4 << endl; 00902 error = true; 00903 } 00904 if (sizeof(F32) != 4 ){ 00905 cout << "Error, size of float is not 32 bytes, it's " << sizeof(F32)*4 << endl; 00906 error = true; 00907 } 00908 if (sizeof(U64) != 8) { 00909 cout << "Error, size of long unsigned int is not 64 bytes, it's " << sizeof(U64)*4 << endl; 00910 error = true; 00911 } 00912 if (sizeof(U32) != 4) { 00913 cout << "Error, size of unsigned int is not 32 bytes, it's " << sizeof(U32)*4 << endl; 00914 error = true; 00915 } 00916 if (sizeof(I16) != 2) { 00917 cout << "Error, size of short int is not 16 bytes, it's " << sizeof(I16)*4 << endl; 00918 error = true; 00919 } 00920 if (sizeof(U16) != 2) { 00921 cout << "Error, size of short unsigned int is not 16 bytes, it's " << sizeof(U16)*4 << endl; 00922 error = true; 00923 } 00924 if (sizeof(U8) != 1) { 00925 cout << "Error, size of unsigned char is not bytes, it's " << sizeof(U8)*4 << endl; 00926 error = true; 00927 } 00928 00929 if (error) { 00930 throw; 00931 } 00932 }
ostream & EMAN::U3DWriter::write | ( | ostream & | os, | |
const string & | s | |||
) |
Definition at line 1131 of file marchingcubes.cpp.
References test_type_sizes(), and write().
01132 { 01133 // WARNING - I AM NOT SURE IF THIS APPROACH WILL PRESENT UTF8 PROBLEMS. 01134 // See character_encoding in the file header writing module above 01135 test_type_sizes(); 01136 01137 short unsigned int size = s.size(); // To write a string you must first place its 01138 write(os,size); 01139 01140 // Write the characters 01141 for(unsigned int i = 0; i<size; ++i) { 01142 write(os,s[i]); 01143 } 01144 01145 return os; 01146 }
ostream& EMAN::U3DWriter::write | ( | ostream & | os, | |
const type & | T | |||
) | [inline, private] |
ostream & U3DWriter::write | ( | ostream & | ) |
Definition at line 854 of file marchingcubes.cpp.
References write_header().
00854 { 00855 write_header(os); 00856 return os; 00857 }
int U3DWriter::write | ( | const string & | filename | ) |
Definition at line 845 of file marchingcubes.cpp.
Referenced by write(), write_clod_mesh_generator_node(), and write_header().
00845 { 00846 // Must open the ofstream in binary mode 00847 ofstream of(filename.c_str(), ofstream::binary); 00848 write(of); 00849 of.close(); 00850 00851 return 1; 00852 }
ostream & U3DWriter::write_clod_mesh_generator_node | ( | ostream & | os | ) | [private] |
Definition at line 934 of file marchingcubes.cpp.
References data, DIFFUSE_COLOR_COUNT, EMAN::CustomVector< type >::elem(), ff, EMAN::CustomVector< type >::get_data(), nn, pp, SPECULAR_COLOR_COUNT, and write().
00935 { 00936 /* 00937 CLOD Mesh Declaration 00938 */ 00939 U32 block_type_clod_mesh_generator = 0xFFFFFF31; // This is the block type tag of the continuous level of detail mesh generator, as taken form the ECMA spec 00940 write( os, block_type_clod_mesh_generator); 00941 00942 string name("testmesh"); // The unique name, we get to make this up ourselves. It could be an empty string, we'd still have to call write_string(os,"") 00943 write(os,name); 00944 00945 U32 chain_index = 0x00000000; // the value of Chain Index shall be zero for this type - as in the SPEC 00946 write( os, chain_index); 00947 00948 /* 00949 Max Mesh Description 00950 */ 00951 U32 mesh_attributes = 0x00000000; // Faces in the mesh have a normal index at each corner 0x00000001 is used to exlude normals POTENTIALLY USEFUL 00952 write(os,mesh_attributes); 00953 U32 face_count = ff.elem(); // The number of faces TO FILL IN LATER 00954 write(os,face_count); 00955 U32 position_count = pp.elem(); // The number of positions in the position array TO FILL IN LATER 00956 write(os,position_count); 00957 U32 normal_count = nn.elem(); // The number of normals in the normal array TO FILL IN LATER 00958 write(os,normal_count); 00959 U32 diffuse_color_count = DIFFUSE_COLOR_COUNT; // The number of colors in the diffuse color array TO FILL IN LATER 00960 write(os,diffuse_color_count); 00961 U32 specular_color_count = SPECULAR_COLOR_COUNT; // The number of colors in the specular color array TO FILL IN LATER 00962 write(os,specular_color_count); 00963 U32 texture_coord_count = 0x00000000; // The number of texture coordinates in teh texture coordinate array POTENTIALLY USEFUL 00964 write(os,texture_coord_count); 00965 U32 shading_count = 1; // The number of shading descriptions used in the mesh. This must correspond with the shader list in the shading group (see directly below we are using only one shader 00966 write(os,shading_count); 00967 00968 /* 00969 Shading Description 00970 */ 00971 U32 shading_attributes = 0x00000003; // 0 means use neither diffuse or specular colors, 1 means use per vertex diffuse, 2 means use per vertex specular, 3 means use both POTENTIALLY USEFUL 00972 write(os,shading_attributes); 00973 U32 texture_layout_count = 0x00000000; // The number of texture layers used by this shader list 00974 write(os,texture_layout_count); 00975 U32 texture_coord_dimensions = 0x00000002; // The number of dimensions in the texture coordinate vector. I chose default to be 2. No particular reason. POTENTIALLY USEFUL 00976 write(os,texture_coord_dimensions); 00977 U32 original_shading_id = 0; // Original shading index for this shader list. Informative parameter only. This is shader 0 00978 write(os,original_shading_id); 00979 00980 /* 00981 CLOD Description - describes the range of resolutions available for the continuous level of detail mesh 00982 If there were more than one level of detail than these two numbers would be different 00983 */ 00984 U32 minimum_resolution = position_count; // the number of positions in the base mesh 00985 write(os,minimum_resolution); 00986 U32 final_maximum_resolution = position_count; // the number of positions in the Max Mesh Description (by definition) 00987 write(os,final_maximum_resolution); 00988 00989 /* 00990 Resource Description 00991 */ 00992 00993 /* 00994 Quality Factors 00995 for information only. Not used by the renderer. Helpful for conveying information to the user 00996 */ 00997 U32 position_quality_factor = 0x00000000; // position quality factor. Descriptive information only 00998 write(os,position_quality_factor); 00999 U32 normal_quality_factor = 0x00000000; // normal quality factor. Descriptive information only 01000 write(os,normal_quality_factor); 01001 U32 texture_coord_quality_factor = 0x00000000; // texture coordinate quality factor. Descriptive information only 01002 write(os,texture_coord_quality_factor); 01003 01004 /* 01005 Inverse Quantization 01006 used to reconstruct floating point values that have been quantized. 01007 */ 01008 F32 postion_inverse_quant = 1.0; // inverse quantization factor used in the reconstruction of the position vectors 01009 write(os,postion_inverse_quant); 01010 F32 normal_inverse_quant = 1.0; // inverse quantization factor used in the reconstruction of the normal vectors 01011 write(os,normal_inverse_quant); 01012 F32 texture_coord_inverse_quant = 1.0; // inverse quantization factor used in the reconstruction of the texture coordinates 01013 write(os,texture_coord_inverse_quant); 01014 F32 diffuse_color_inverse_quant = 1.0; // inverse quantization factor used in the reconstruction of the diffuse colors 01015 write(os,diffuse_color_inverse_quant); 01016 F32 specular_color_inverse_quant = 1.0; // inverse quantization factor used in the reconstruction of the specular colors 01017 write(os,specular_color_inverse_quant); 01018 01019 /* 01020 Resource Parameters 01021 parameters that help to define the conversion from the Author Mesh format to the Render Mesh format 01022 */ 01023 01024 F32 normal_crease_parameter = 1.0; // A dot product value in the range -1 to 1, used to decide whether or not normals at the same position will be merged. 1.0 means never, -1.0 means always. 0 means the two normals must be separated by an angle no greater than 90 degrees to be merged. Think in angles. 01025 write(os,normal_crease_parameter); 01026 F32 normal_update_parameter = 0.0; // A strange a parameter that I couldn't make sense of - I think it means it will change the actual file itself if it encounters what it deems 'normal errors' 01027 write(os,normal_update_parameter); 01028 F32 normal_tolerance_parameter = 0.0; // Normals which are closer together than this value are considered equivalent in the Render Mesh. This is useful for compression 01029 write(os,normal_tolerance_parameter); 01030 01031 /* 01032 Skeleton description 01033 used in bones-based animation by the Animation Modifier 01034 */ 01035 U32 bone_count = 0x00000000; // The number of bones associated with this mesh. We will always have 0, but this could change (unlikely). 01036 write(os,bone_count); 01037 01038 // WARNING - if bone_count is ever greater than one, then more writing would have to occur here 01039 01041 /* 01042 Base mesh is basically the minimum LOD mesh - it must exist 01043 */ 01044 { 01045 U32 block_type_clod_base_mesh_continuation = 0xFFFFFF3B; // This is the block type tag of the CLOD Base Mesh Continuation, as taken form the ECMA spec 01046 write( os, block_type_clod_base_mesh_continuation); 01047 01048 write(os,name); // We use the same name as above 01049 01050 U32 chain_index = 0x00000000; // the value of Chain Index shall be zero for this type - as in the SPEC 01051 write( os, chain_index); 01052 01053 /* 01054 Base Mesh Description 01055 */ 01056 U32 base_face_count = ff.elem(); // The number of faces in the base mesh TO FILL IN LATER 01057 write( os, base_face_count); 01058 U32 base_position_count = pp.elem(); // The number of positions used by base mesh in the position array TO FILL IN LATER 01059 write( os, base_position_count); 01060 U32 base_normal_count = nn.elem(); // The number of normals used by the base mesh in the normal array TO FILL IN LATER 01061 write( os, base_normal_count); 01062 U32 base_diffuse_color_count = DIFFUSE_COLOR_COUNT; // The number of diffuse colors used by the base mesh in the diffuse color array TO FILL IN LATER 01063 write( os, base_diffuse_color_count); 01064 U32 base_specular_color_count = SPECULAR_COLOR_COUNT; // The number of specular colors used by the base mesh in the specular color array TO FILL IN LATER 01065 write( os, base_specular_color_count); 01066 U32 base_texture_coord_count = 0x00000000; // The number of texture coordinates used by the base mesh in texture coordinate array TO FILL IN LATER 01067 write( os, base_texture_coord_count); 01068 01069 /* 01070 Base mesh data 01071 */ 01072 01073 // Write position data 01074 F32* data = pp.get_data(); 01075 for(unsigned int i = 0; i < pp.elem(); ++i) { 01076 write(os,data[i]); 01077 } 01078 01079 // Write normal data 01080 data = nn.get_data(); 01081 for(unsigned int i = 0; i < nn.elem(); ++i) { 01082 write(os,data[i]); 01083 } 01084 01085 // Write Diffuse color, this is in rgba format 01086 F32 diffuse_rgba[4] = {1.0,0.0,0.0,1.0}; 01087 for (unsigned int i = 0; i < 4; ++i) { 01088 write(os,diffuse_rgba[i]); 01089 } 01090 01091 // Write Specular color, this is in rgba format 01092 F32 specular_rgba[4] = {1.0,0.0,0.0,1.0}; 01093 for (unsigned int i = 0; i < 4; ++i) { 01094 write(os,specular_rgba[i]); 01095 } 01096 01097 // THERE ARE NO TEXTURE COORDINATES, BUT IF THERE WERE WE WOULD HAVE TO WRITE THEM HERE 01098 // i.e. for i in range(0,base_texture_coord_count) write texture coords 01099 01100 // Write normal data 01101 U32* faces = ff.get_data(); 01102 for(unsigned int i = 0; i < pp.elem(); i = i+3) { 01103 U32 shading_id = 0; // We only have one shader defined. This could could changed in future 01104 write(os,shading_id); 01105 01106 // write base corner info - there are always three corners 01107 for (unsigned int j =0; j < 3; ++j){ 01108 U32 position_index = faces[i+j]; 01109 write(os,position_index); // Write the position index 01110 01111 U32 normal_index = position_index; 01112 write(os,normal_index); // Write the normal index, it is exactly the same as the normal index! 01113 01114 U32 base_diffuse_color_index = 0; // only using one diffuse color 01115 write(os,base_diffuse_color_index); 01116 01117 U32 base_specular_color_index = 0; // only using one specular color 01118 write(os,base_specular_color_index); 01119 01120 // Would need to write texture data here if we were doing that 01121 01122 } 01123 01124 } 01125 01126 } 01127 return os; 01128 }
ostream & U3DWriter::write_header | ( | ostream & | ) | [private] |
Definition at line 865 of file marchingcubes.cpp.
References size_of_in_bytes(), test_type_sizes(), and write().
Referenced by write().
00866 { 00867 // checks 00868 test_type_sizes(); 00869 00870 U32 block_type_file_header = 0x00443355; // This is the block type tag of a file header, as taken form the ECMA spec 00871 write( os, block_type_file_header); 00872 // 00873 I16 major_version = -1; // Compliance has not been tested for this encoder, so we must specify a value less than 0 00874 I16 minor_version = 0; // This is the version of this encoder, which we are calling '0' 00875 write( os, major_version); 00876 write( os, minor_version); 00877 00878 U32 profile_identifier = 0x00000000; // Base profile - no optional features ares used 00879 write( os, profile_identifier); 00880 00881 U32 declaration_size = size_of_in_bytes(); // This will have to be addressed at a later point, this is the size if the declaration block in bytes 00882 write( os, declaration_size); 00883 00884 U64 file_size = size_of_in_bytes(); // This is the size of the file in bytes 00885 write( os, file_size); 00886 00887 U32 character_encoding = 106; // UTF-8 MIB from the IANA 00888 write( os, character_encoding); 00889 00890 F64 unit_scaling = 1.0; // This should eventually be the correct scaling of the objects 00891 write( os, unit_scaling); 00892 00893 00894 return os; 00895 }
U32 EMAN::U3DWriter::DIFFUSE_COLOR_COUNT [private] |
CustomVector<unsigned int> EMAN::U3DWriter::ff [private] |
CustomVector<F32> EMAN::U3DWriter::nn [private] |
CustomVector<F32> EMAN::U3DWriter::pp [private] |
U32 EMAN::U3DWriter::SPECULAR_COLOR_COUNT [private] |