VRUT::IOImageModule Class Reference

IMAGE import/export module class. More...

#include <ioimage.h>

Inheritance diagram for VRUT::IOImageModule:

VRUT::IOModule VRUT::SceneModule VRUT::Module

List of all members.

Public Member Functions

 IOImageModule (const MODULE_ID &_id, const wxString &_name, EventHandler *msgSink)
 Class constructor.
virtual ~IOImageModule ()
 Class destructor.
virtual wxString GetDesc () const
 Get module description - Module overload.
virtual wxString GetSupportedExts () const
 Get string with file extensions supported by module - IOModule overload.
virtual bool ImportScene (const wxString &fname, SCENE_ID sceneID, const wxString &rootUid)
virtual bool ExportScene (const wxString &fname, const Scene *scene)
 Export scene to file.


Detailed Description

IMAGE import/export module class.

Definition at line 24 of file ioimage.h.


Constructor & Destructor Documentation

IOImageModule::IOImageModule ( const MODULE_ID _id,
const wxString &  _name,
EventHandler msgSink 
)

Class constructor.

Listen to scene changes

Definition at line 20 of file ioimage.cpp.

00021               : IOModule(_id, _name, 0, msgSink)
00022 {
00024        REGISTER_LISTENER(Event::EVT_SCENE_IMAGE_ADDED);
00025 }

IOImageModule::~IOImageModule (  )  [virtual]

Class destructor.

Definition at line 28 of file ioimage.cpp.

00029 {
00030 }


Member Function Documentation

wxString IOImageModule::GetDesc (  )  const [virtual]

Get module description - Module overload.

Implements VRUT::Module.

Definition at line 33 of file ioimage.cpp.

00034 {
00035        return wxT("Import and export images");
00036 }

wxString IOImageModule::GetSupportedExts (  )  const [virtual]

Get string with file extensions supported by module - IOModule overload.

Implements VRUT::IOModule.

Definition at line 39 of file ioimage.cpp.

00040 {
00041        return wxT("BMP,PNG,JPG,JPEG,GIF,PCX,PNM,TIF,TIFF,TGA,IFF,XPM,ICO,CUR,ANI,RGB");
00042 }

bool IOImageModule::ImportScene ( const wxString &  fname,
SCENE_ID  sceneID,
const wxString &  rootUid 
) [virtual]

Import scene from file - SceneIOModule overload

Parameters:
[in] fname Path to scene files (archive)
[in] sceneID ID of scene to be filled with data
[in] rootUid Uid of node where to start filling
Returns:
True if successful

Create new mesh

Add geometry to scene

Assign geometry to node

Implements VRUT::IOModule.

Definition at line 45 of file ioimage.cpp.

00046 {
00047        wxStopWatch sw;
00048        bool ret = false;
00049 
00050        //create material
00051        Material * material = new Material(rootUid);
00052        material->diffuse = VECTOR4(1, 1, 1, 1);
00053        material->specular = VECTOR4(0, 0, 0, 1);
00054        material->shininess = 16;
00055        material->flags |= Material::DOUBLE_SIDED;
00056        material->depthFunc = 203;
00057        wxCommandEvent ev1(Event::GET_EVT_SCENE_IMAGE_ADD(fname));
00058        PostToKernel(ev1);
00059        material->imageName = fname;
00060        material->texFlags |= Material::TEX_UWRAP_REPEAT;
00061        material->texFlags |= Material::TEX_VWRAP_REPEAT;
00062        material->texFlags |= Material::TEX_MIN_FILTER_MIPMAP;
00063        material->texFlags |= Material::TEX_MAG_FILTER_LINEAR;
00064        material->texFlags |= Material::TEX_ENV_MODULATE;
00065        wxCommandEvent ev2(Event::GET_EVT_SCENE_MATERIAL_ADD(sceneID, material));
00066        PostToKernel(ev2);
00067        WaitForEvent(Event::EVT_SCENE_IMAGE_ADDED, 10000, -1, -1, fname);
00068        const Image * img = (GetSceneMgr()->GetScene(sceneID))->GetImage(fname);
00069        int width = 1, height = 1;
00070        if (!img || !img->IsOk())
00071        {
00072               LOGERROR(wxT("<IOImageModule>Image cannot be loaded."));
00073               return false;
00074        }
00075        else
00076        {
00077               width = img->GetWidth();
00078               height = img->GetHeight();
00079               if (img->HasTransparency())
00080               {
00081                      material->flags |= Material::BLENDED;
00082                      material->texBlendSrc = GL_SRC_ALPHA;
00083                      material->texBlendDst = GL_ONE;
00084               }
00085        }
00086        //create geometry
00087        GeometryNode *node = new GeometryNode(rootUid+wxT("Geometry"), rootUid+wxT("Geometry"));
00088        wxCommandEvent ev3(Event::GET_EVT_SCENE_NODE_INSERT(sceneID, node, rootUid));
00089        PostToKernel(ev3);
00090 
00091        //add material to the geometry node
00092        wxCommandEvent ev4(Event::GET_EVT_SCENE_NODE_MATERIAL_SET(sceneID, rootUid+wxT("Geometry"), rootUid));
00093        PostToKernel(ev4);
00094 
00096        GeometryTriangles *geometry = new GeometryTriangles(rootUid+wxT("Geometry"));
00097        std::vector<VECTOR3> * verts = &(geometry->vertices);
00098        std::vector<VECTOR3> * normals = &(geometry->normals);
00099        std::vector<GeometryTriangles::TexCoord> * texCoords = &(geometry->texCoords);
00100        verts->push_back(VECTOR3(0,0,0));
00101        verts->push_back(VECTOR3(width,0,0));
00102        verts->push_back(VECTOR3(0,height,0));
00103        verts->push_back(VECTOR3(width,height,0));
00104        normals->push_back(VECTOR3(0,0,1));
00105        normals->push_back(VECTOR3(0,0,1));
00106        normals->push_back(VECTOR3(0,0,1));
00107        normals->push_back(VECTOR3(0,0,1));
00108        texCoords->push_back(GeometryTriangles::TexCoord(0,0));
00109        texCoords->push_back(GeometryTriangles::TexCoord(1,0));
00110        texCoords->push_back(GeometryTriangles::TexCoord(0,1));
00111        texCoords->push_back(GeometryTriangles::TexCoord(1,1));
00112        std::vector<GeometryTriangles::Indice> * indices = &(geometry->indices);
00113        GeometryTriangles::TriDescList * triDescList = &geometry->triDescList;
00114        std::pair<GeometryTriangles::Indice, GeometryTriangles::PRIMITIVE_TYPE> indType((GeometryTriangles::Indice)indices->size(), GeometryTriangles::TRI_STRIP);
00115        triDescList->push_back(indType);
00116        indices->push_back((GeometryTriangles::Indice)0);
00117        indices->push_back((GeometryTriangles::Indice)1);
00118        indices->push_back((GeometryTriangles::Indice)2);
00119        indices->push_back((GeometryTriangles::Indice)3);
00120 
00122        wxCommandEvent ev5(Event::GET_EVT_SCENE_GEOMETRY_ADD(sceneID, geometry));
00123        PostToKernel(ev5);
00125        wxCommandEvent ev6(Event::GET_EVT_SCENE_NODE_GEOMETRY_SET(sceneID, rootUid+wxT("Geometry"), geometry->GetName()));
00126        PostToKernel(ev6);
00127 
00128        LOG(wxString::Format(wxT("<IOImageModule>Scene parsed in %.3f secs, ID %i"), 0.001f * sw.Time(), sceneID));
00129        wxCommandEvent ev7(Event::GET_EVT_IO_SCENE_IMPORT_DONE(sceneID));
00130        PostToKernel(ev7);
00131        return ret;
00132 }

bool IOImageModule::ExportScene ( const wxString &  fname,
const Scene scene 
) [virtual]

Export scene to file.

Implements VRUT::IOModule.

Definition at line 135 of file ioimage.cpp.

00136 {
00137 /*     wxOutputStream * sceneStream = new wxFileOutputStream(fname);
00138        if (sceneStream && sceneStream->IsOk())
00139        {
00140               STLWriter stlWriter(sceneStream, scene);
00141               stlWriter.Write(saveBinary);
00142               return true;
00143        }*/
00144        return false;
00145 }


The documentation for this class was generated from the following files:

Generated on Tue Mar 10 14:41:40 2009 for VRUT by  doxygen 1.5.5