Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

EMAN::U3DWriter Class Reference

A work in progress by David Woolford. More...

#include <marchingcubes.h>

Collaboration diagram for EMAN::U3DWriter:

Collaboration graph
[legend]
List of all members.

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 &)

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< F32pp
CustomVector< F32nn
CustomVector< unsigned int > ff

Detailed Description

A work in progress by David Woolford.

Definition at line 364 of file marchingcubes.h.


Member Typedef Documentation

typedef float EMAN::U3DWriter::F32
 

Definition at line 369 of file marchingcubes.h.

Referenced by write_clod_mesh_generator_node().

typedef double EMAN::U3DWriter::F64
 

Definition at line 368 of file marchingcubes.h.

Referenced by write_header().

typedef short int EMAN::U3DWriter::I16
 

Definition at line 370 of file marchingcubes.h.

Referenced by write_header().

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.

Referenced by write_clod_mesh_generator_node(), and write_header().

typedef long unsigned int EMAN::U3DWriter::U64
 

Definition at line 367 of file marchingcubes.h.

Referenced by write_header().

typedef unsigned char EMAN::U3DWriter::U8
 

Definition at line 372 of file marchingcubes.h.


Constructor & Destructor Documentation

U3DWriter::U3DWriter  ) 
 

Definition at line 836 of file marchingcubes.cpp.

00836                      : DIFFUSE_COLOR_COUNT(1),
00837                 SPECULAR_COLOR_COUNT(1)
00838 {
00839 }

U3DWriter::~U3DWriter  ) 
 

Definition at line 840 of file marchingcubes.cpp.

00840 {}


Member Function Documentation

unsigned int U3DWriter::size_of_in_bytes  )  [private]
 

Definition at line 858 of file marchingcubes.cpp.

Referenced by write_header().

00858                                         {
00859         // this is just the size in bytes of all of the entries in this object that are written to the binary
00860         // output. This is based only on the behavior of write_header and needs to be udpated
00861         unsigned size = 4+2+2+4+4+8+4+8; // 36 bytes
00862         return size;
00863 }

void U3DWriter::test_type_sizes  )  [private]
 

Definition at line 896 of file marchingcubes.cpp.

Referenced by write_header().

00897 {
00898         bool error = false;
00899         if (sizeof(F64) != 8 ){
00900                 cout << "Error, size of double is not 64 bytes, it's " << sizeof(F64)*4 << endl;
00901                 error = true;
00902         }
00903         if (sizeof(F32) != 4 ){
00904                 cout << "Error, size of float is not 32 bytes, it's " << sizeof(F32)*4 << endl;
00905                 error = true;
00906         }
00907         if (sizeof(U64) != 8) {
00908                 cout << "Error, size of long unsigned int is not 64 bytes, it's " << sizeof(U64)*4 << endl;
00909                 error = true;
00910         }
00911         if (sizeof(U32) != 4) {
00912                 cout << "Error, size of unsigned int is not 32 bytes, it's " << sizeof(U32)*4 << endl;
00913                 error = true;
00914         }
00915         if (sizeof(I16) != 2) {
00916                 cout << "Error, size of short int is not 16 bytes, it's " << sizeof(I16)*4 << endl;
00917                 error = true;
00918         }
00919         if (sizeof(U16) != 2) {
00920                 cout << "Error, size of short unsigned int is not 16 bytes, it's " << sizeof(U16)*4 << endl;
00921                 error = true;
00922         }
00923         if (sizeof(U8) != 1) {
00924                 cout << "Error, size of unsigned char is not  bytes, it's " << sizeof(U8)*4 << endl;
00925                 error = true;
00926         }
00927 
00928         if (error) {
00929                 throw;
00930         }
00931 }

template<typename type>
ostream& EMAN::U3DWriter::write ostream &  os,
const type &  T
[inline, private]
 

Definition at line 393 of file marchingcubes.h.

00393                                                            {
00394                         os.write( (const char*)(&T), sizeof(type) );
00395                         return os;
00396                 }

ostream & U3DWriter::write ostream &   ) 
 

Definition at line 853 of file marchingcubes.cpp.

References write_header().

00853                                      {
00854         write_header(os);
00855         return os;
00856 }

int U3DWriter::write const string &  filename  ) 
 

Definition at line 844 of file marchingcubes.cpp.

Referenced by write_clod_mesh_generator_node(), and write_header().

00844                                            {
00845         // Must open the ofstream in binary mode
00846         ofstream of(filename.c_str(), ofstream::binary);
00847         write(of);
00848         of.close();
00849 
00850         return 1;
00851 }

ostream & U3DWriter::write_clod_mesh_generator_node ostream &  os  )  [private]
 

Definition at line 933 of file marchingcubes.cpp.

References data, EMAN::CustomVector< type >::elem(), F32, ff, EMAN::CustomVector< type >::get_data(), nn, pp, U32, and write().

00934 {
00935         /*
00936         CLOD Mesh Declaration
00937         */
00938         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
00939         write( os, block_type_clod_mesh_generator);
00940 
00941         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,"")
00942         write(os,name);
00943 
00944         U32 chain_index = 0x00000000; // the value of Chain Index shall be zero for this type - as in the SPEC
00945         write( os, chain_index);
00946 
00947         /*
00948         Max Mesh Description
00949         */
00950         U32 mesh_attributes = 0x00000000; // Faces in the mesh have a normal index at each corner 0x00000001 is used to exlude normals POTENTIALLY USEFUL
00951         write(os,mesh_attributes);
00952         U32 face_count = ff.elem(); // The number of faces TO FILL IN LATER
00953         write(os,face_count);
00954         U32 position_count = pp.elem(); // The number of positions in the position array TO FILL IN LATER
00955         write(os,position_count);
00956         U32 normal_count = nn.elem(); // The number of normals in the normal array TO FILL IN LATER
00957         write(os,normal_count);
00958         U32 diffuse_color_count = DIFFUSE_COLOR_COUNT; // The number of colors in the diffuse color array TO FILL IN LATER
00959         write(os,diffuse_color_count);
00960         U32 specular_color_count = SPECULAR_COLOR_COUNT; // The number of colors in the specular color array TO FILL IN LATER
00961         write(os,specular_color_count);
00962         U32 texture_coord_count = 0x00000000; // The number of texture coordinates in teh texture coordinate array POTENTIALLY USEFUL
00963         write(os,texture_coord_count);
00964         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
00965         write(os,shading_count);
00966 
00967         /*
00968         Shading  Description
00969         */
00970         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
00971         write(os,shading_attributes);
00972         U32 texture_layout_count = 0x00000000; // The number of texture layers used by this shader list
00973         write(os,texture_layout_count);
00974         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
00975         write(os,texture_coord_dimensions);
00976         U32 original_shading_id = 0; // Original shading index for this shader list. Informative parameter only. This is shader 0
00977         write(os,original_shading_id);
00978 
00979         /*
00980         CLOD Description - describes the range of resolutions available for the continuous level of detail mesh
00981         If there were more than one level of detail than these two numbers would be different
00982         */
00983         U32 minimum_resolution = position_count; // the number of positions in the base mesh
00984         write(os,minimum_resolution);
00985         U32 final_maximum_resolution = position_count; // the number of positions in the Max Mesh Description (by definition)
00986         write(os,final_maximum_resolution);
00987 
00988         /*
00989         Resource Description
00990         */
00991 
00992         /*
00993         Quality Factors
00994         for information only. Not used by the renderer. Helpful for conveying information to the user
00995         */
00996         U32 position_quality_factor = 0x00000000; // position quality factor. Descriptive information only
00997         write(os,position_quality_factor);
00998         U32 normal_quality_factor = 0x00000000; // normal quality factor. Descriptive information only
00999         write(os,normal_quality_factor);
01000         U32 texture_coord_quality_factor = 0x00000000; // texture coordinate quality factor. Descriptive information only
01001         write(os,texture_coord_quality_factor);
01002 
01003         /*
01004         Inverse Quantization
01005         used to reconstruct floating point values that have been quantized.
01006         */
01007         F32 postion_inverse_quant = 1.0; // inverse quantization factor used in the reconstruction of the position vectors
01008         write(os,postion_inverse_quant);
01009         F32 normal_inverse_quant = 1.0; // inverse quantization factor used in the reconstruction of the normal vectors
01010         write(os,normal_inverse_quant);
01011         F32 texture_coord_inverse_quant = 1.0; // inverse quantization factor used in the reconstruction of the texture coordinates
01012         write(os,texture_coord_inverse_quant);
01013         F32 diffuse_color_inverse_quant = 1.0; // inverse quantization factor used in the reconstruction of the diffuse colors
01014         write(os,diffuse_color_inverse_quant);
01015         F32 specular_color_inverse_quant = 1.0; // inverse quantization factor used in the reconstruction of the specular colors
01016         write(os,specular_color_inverse_quant);
01017 
01018         /*
01019         Resource Parameters
01020         parameters that help to define the conversion from the Author Mesh format to the Render Mesh format
01021         */
01022 
01023         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.
01024         write(os,normal_crease_parameter);
01025         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'
01026         write(os,normal_update_parameter);
01027         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
01028         write(os,normal_tolerance_parameter);
01029 
01030         /*
01031         Skeleton description
01032         used in bones-based animation by the Animation Modifier
01033         */
01034         U32 bone_count = 0x00000000; // The number of bones associated with this mesh. We will always have 0, but this could change (unlikely).
01035         write(os,bone_count);
01036 
01037         // WARNING - if bone_count is ever greater than one, then more writing would have to occur here
01038 
01040         /*
01041         Base mesh is basically the minimum LOD mesh - it must exist
01042         */
01043         {
01044         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
01045         write( os, block_type_clod_base_mesh_continuation);
01046 
01047         write(os,name); // We use the same name as above
01048 
01049         U32 chain_index = 0x00000000; // the value of Chain Index shall be zero for this type - as in the SPEC
01050         write( os, chain_index);
01051 
01052         /*
01053         Base Mesh Description
01054         */
01055         U32     base_face_count = ff.elem(); // The number of faces in the base mesh TO FILL IN LATER
01056         write( os, base_face_count);
01057         U32     base_position_count = pp.elem(); // The number of positions used by base mesh in the position array TO FILL IN LATER
01058         write( os, base_position_count);
01059         U32 base_normal_count = nn.elem(); // The number of normals used by the base mesh in the normal array TO FILL IN LATER
01060         write( os, base_normal_count);
01061         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
01062         write( os, base_diffuse_color_count);
01063         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
01064         write( os, base_specular_color_count);
01065         U32 base_texture_coord_count = 0x00000000; // The number of texture coordinates used by the base mesh in texture coordinate array TO FILL IN LATER
01066         write( os, base_texture_coord_count);
01067 
01068         /*
01069         Base mesh data
01070         */
01071 
01072         // Write position data
01073         F32* data = pp.get_data();
01074         for(unsigned int i = 0; i < pp.elem(); ++i) {
01075                 write(os,data[i]);
01076         }
01077 
01078         // Write normal data
01079         data = nn.get_data();
01080         for(unsigned int i = 0; i < nn.elem(); ++i) {
01081                 write(os,data[i]);
01082         }
01083 
01084         // Write Diffuse color, this is in rgba format
01085         F32 diffuse_rgba[4] = {1.0,0.0,0.0,1.0};
01086         for (unsigned int i = 0; i < 4; ++i) {
01087                 write(os,diffuse_rgba[i]);
01088         }
01089 
01090         // Write Specular color, this is in rgba format
01091         F32 specular_rgba[4] = {1.0,0.0,0.0,1.0};
01092         for (unsigned int i = 0; i < 4; ++i) {
01093                 write(os,specular_rgba[i]);
01094         }
01095 
01096         // THERE ARE NO TEXTURE COORDINATES, BUT IF THERE WERE WE WOULD HAVE TO WRITE THEM HERE
01097         // i.e. for i in range(0,base_texture_coord_count) write texture coords
01098 
01099         // Write normal data
01100         U32* faces = ff.get_data();
01101         for(unsigned int i = 0; i < pp.elem(); i = i+3) {
01102                 U32 shading_id = 0; // We only have one shader defined. This could could changed in future
01103                 write(os,shading_id);
01104 
01105                 // write base corner info - there are always three corners
01106                 for (unsigned int j =0; j < 3; ++j){
01107                         U32 position_index = faces[i+j];
01108                         write(os,position_index); // Write the position index
01109 
01110                         U32 normal_index = position_index;
01111                         write(os,normal_index); // Write the normal index, it is exactly the same as the normal index!
01112 
01113                         U32 base_diffuse_color_index = 0; // only using one diffuse color
01114                         write(os,base_diffuse_color_index);
01115 
01116                         U32 base_specular_color_index = 0; // only using one specular color
01117                         write(os,base_specular_color_index);
01118 
01119                         // Would need to write texture data here if we were doing that
01120 
01121                 }
01122 
01123         }
01124 
01125         }
01126         return os;
01127 }

ostream & U3DWriter::write_header ostream &   )  [private]
 

Definition at line 864 of file marchingcubes.cpp.

References F64, I16, size_of_in_bytes(), test_type_sizes(), U32, U64, and write().

Referenced by write().

00865 {
00866         // checks
00867         test_type_sizes();
00868 
00869         U32 block_type_file_header = 0x00443355; // This is the block type tag of a file header, as taken form the ECMA spec
00870         write( os, block_type_file_header);
00871 //
00872         I16 major_version = -1; // Compliance has not been tested for this encoder, so we must specify a value less than 0
00873         I16 minor_version =  0; // This is the version of this encoder, which we are calling '0'
00874         write( os, major_version);
00875         write( os, minor_version);
00876 
00877         U32 profile_identifier = 0x00000000; // Base profile - no optional features ares used
00878         write( os, profile_identifier);
00879 
00880         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
00881         write( os, declaration_size);
00882 
00883         U64 file_size = size_of_in_bytes(); // This is the size of the file in bytes
00884         write( os, file_size);
00885 
00886         U32 character_encoding = 106; // UTF-8 MIB from the IANA
00887         write( os, character_encoding);
00888 
00889         F64 unit_scaling = 1.0; // This should eventually be the correct scaling of the objects
00890         write( os, unit_scaling);
00891 
00892 
00893         return os;
00894 }


Member Data Documentation

U32 EMAN::U3DWriter::DIFFUSE_COLOR_COUNT [private]
 

Definition at line 468 of file marchingcubes.h.

CustomVector<unsigned int> EMAN::U3DWriter::ff [private]
 

Definition at line 474 of file marchingcubes.h.

Referenced by write_clod_mesh_generator_node().

CustomVector<F32> EMAN::U3DWriter::nn [private]
 

Definition at line 473 of file marchingcubes.h.

Referenced by write_clod_mesh_generator_node().

CustomVector<F32> EMAN::U3DWriter::pp [private]
 

Definition at line 472 of file marchingcubes.h.

Referenced by write_clod_mesh_generator_node().

U32 EMAN::U3DWriter::SPECULAR_COLOR_COUNT [private]
 

Definition at line 469 of file marchingcubes.h.


The documentation for this class was generated from the following files:
Generated on Tue Jul 12 13:51:33 2011 for EMAN2 by  doxygen 1.3.9.1