Community
DWF
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DWF geometry data

21 REPLIES 21
Reply
Message 1 of 22
bejn
2282 Views, 21 Replies

DWF geometry data

I've just started looking at the DWF Toolkit, with the aim of extracting the geometry data from a DWF file so that I can visualize it with OpenGL.

I could not find any examples on how to extract the object geometry, is there such an example available? If not, would it be possible to get a small code snippet on how to do this, to point me in the right direction?

Thanks in advance
Bjorn
21 REPLIES 21
Message 2 of 22
jasona
in reply to: bejn

Bjorn,

There are two ways of parsing geometry data in a dwf file. This depends on whether the stream is a 2d or 3d stream. Basically you do as follows :

NOTES :
Pasted code is from my application, and may have irrelevant information, just ignore and read the documentation.
I am not performing memory management, so you must ensure you do this.
I am not performing error checking, but obviuosly you must in your application.

step 1.

Find out if you are dealing with a package or a stream.

DWFFile file( pwszFile );
DWFPackageReader PkgRdr( file );
DWFPackageReader::tPackageInfo packInfo;
PkgRdr.getPackageInfo( packInfo );
switch (tInfo.eType) {
case DWFToolkit::DWFPackageReader::eDWFPackage:
// deal with a package
break;
case DWFToolkit::DWFPackageReader::eW2DStream:
//deal with a2d stream
break;
case DWFToolkit::DWFPackageReader::eDWFStream:
// deal with a eDWF Stream
break;
case DWFToolkit::DWFPackageReader::eDWFPackageEncrypted:
// password protected package.
break;
default:
return false;
}

step 2.

So if it is a package, we can find the layouts (sections) as follows :

DWFManifest &Manf = PkgRdr.getManifest();
DWFSection* pSection = NULL;
DWFManifest::SectionIterator* pSections = NULL;
for ( pSections = Manf.getSections();
pSections && pSections->valid(); pSections->next() ) {
pSection = pSections->get();

if ( (pSection->type() == _DWF_FORMAT_EPLOT_TYPE_WIDE_STRING ) ||
(pSection->type() == _DWF_FORMAT_EMODEL_TYPE_WIDE_STRING ) ) {
std::wstring wsCurView = (const wchar_t*)pSection->name();
}

// ok we have a section so next we get the stream for the geometry data.
}


step 3.

So now we have a layout, we can get the stream.
2d streams are as follows :

DWFToolkit::DWFResourceContainer::ResourceIterator* piRes = pSect->findResourcesByRole( DWFXML::kzRole_Graphics2d );
DWFCore::DWFInputStream* pW2DStream = piRes->get()->getInputStream();


3d streams are as follows :

DWFToolkit::DWFResourceContainer::ResourceIterator* piRes = pSect->findResourcesByRole( DWFXML::kzRole_Graphics3d );
DWFToolkit::DWFGraphicResource* pW3D = dynamic_cast(piRes->get()); DWFCore::DWFInputStream* pW3DStream = pW3D->getInputStream();

step 4.

Laslty you must parse the stream with the correct part of the tool kit.
2d streams use the whip toolkit.
3d streams use the hoops scenegraph.

Look in the examples section and this should help you, as this is where I started from.

But basically for the 2d streams I do as follows :
m_pDwf2DStrm = pW2DStream ;
m_pW2DStrm = new WT_File();
m_pW2DStrm->set_stream_open_action(&CWhipHndlr::Open);
m_pW2DStrm->set_stream_close_action (&CWhipHndlr::Close);
m_pW2DStrm->set_stream_read_action (&CWhipHndlr::Read);
m_pW2DStrm->set_stream_seek_action (&CWhipHndlr::Seek);
m_pW2DStrm->set_stream_end_seek_action (&CWhipHndlr::EndSeek);

and the CWhipHndlr functions are callbacks as follows :

WT_Result CWhipHndlr::Open(WT_File & file) {

file.set_stream_user_data (m_pDwf2DStrm);
return m_pDwf2DStrm ?
WT_Result::Success :
WT_Result::File_Open_Error;
}

//---------------------------------------------------------------------------------

WT_Result CWhipHndlr::Close (WT_File & file)
{
return WT_Result::Success;
}

//---------------------------------------------------------------------------------

WT_Result CWhipHndlr::Read( WT_File & file,
int desired_bytes,
int & bytes_read,
void * buffer)
{
WT_Result res = WT_Result::Unknown_File_Read_Error;
if (m_pDwf2DStrm)
{
bytes_read = (int)m_pDwf2DStrm->read (buffer, desired_bytes);
res = WT_Result::Success;
}

return res;
}

//---------------------------------------------------------------------------------

WT_Result CWhipHndlr::Seek( WT_File & file,
int desired_bytes,
int &bytes_seeked)
{
WT_Result res = WT_Result::Unknown_File_Read_Error;
if (m_pDwf2DStrm)
{
m_pDwf2DStrm->seek (SEEK_SET, desired_bytes);
bytes_seeked = desired_bytes;
res = WT_Result::Success;
}

return res;
}

//---------------------------------------------------------------------------------

WT_Result CWhipHndlr::EndSeek (WT_File & file)
{
WT_Result res = WT_Result::Unknown_File_Read_Error;
return res;
}

//---------------------------------------------------------------------------------

WT_Result CWhipHndlr::Tell ( WT_File & file,
unsigned long *current_file_pointer_position )
{
WT_Result res = WT_Result::Unknown_File_Read_Error;
if (m_pDwf2DStrm)
{
*current_file_pointer_position =
m_pDwf2DStrm->seek (SEEK_CUR, 0);
res = WT_Result::Success;
}

return res;
}

and I use the callbacks for all the geometry type like :
m_pW2DStrm->set_polyline_action(CWhipHndlr::prcsPolyLine);
m_pW2DStrm->set_units_action(CWhipHndlr::prcsUnits);
m_pW2DStrm->set_text_action(CWhipHndlr::prcsText);
m_pW2DStrm->set_polygon_action(CWhipHndlr::prcsPolygon);
m_pW2DStrm->set_polytriangle_action(CWhipHndlr::prcsPolyTri);
m_pW2DStrm->set_layer_action(CWhipHndlr::prcsLyr);
m_pW2DStrm->set_color_action(CWhipHndlr::prcsClr);
m_pW2DStrm->set_fill_action(CWhipHndlr::prcsFill);
m_pW2DStrm->set_contour_set_action(CWhipHndlr::prcsContSet);
m_pW2DStrm->set_background_action(CWhipHndlr::prcsBckGrnd);
m_pW2DStrm->set_image_action(CWhipHndlr::prcsImage);
m_pW2DStrm->set_png_group4_image_action(CWhipHndlr::prcsPngImge4);
m_pW2DStrm->set_object_node_action(CWhipHndlr::prcsObjNode);
m_pW2DStrm->set_outline_ellipse_action(CWhipHndlr::prcsOutLineElps);
m_pW2DStrm->set_filled_ellipse_action(CWhipHndlr::prcsFilledElps);
m_pW2DStrm->set_viewport_action(CWhipHndlr::prcsViewPort);
m_pW2DStrm->set_line_weight_action(CWhipHndlr::prcsLineWght);
m_pW2DStrm->set_origin_action(CWhipHndlr::prcsOrgn);

and finally you process each object in the file with the following loop:
while ( res == WT_Result::Success ) {

res = m_pW2DStrm->process_next_object(); // this will call the correct callback for the correct object

// optional section if you wish to do other things as well.
if ( res == WT_Result::Success ) {
WT_Object* pObj = (WT_Object *) m_pW2DStrm->current_object();
if ( pObj ) {
prntDbgObjType(pObj);
WT_Object::WT_ID type = pObj->object_id();
switch ( pObj->object_id() )
{
case WT_Object::DWF_Header_ID :
case WT_Object::End_Of_DWF_ID :
// do any extra work if need be
break;
case WT_Object::Color_Map_ID :
break;
default:
break;
}
}
}
// end of optional section.
}


for 3d its like this

BStreamFileToolkit oW3DStreamParser;
oW3DStreamParser.SetOpcodeHandler( TKE_Open_Segment, new COpenSgmtHndlr(pCtxt.get()));
oW3DStreamParser.SetOpcodeHandler( TKE_Close_Segment, new CCloseSgmtHndlr(pCtxt.get()));
oW3DStreamParser.SetOpcodeHandler( TKE_Polygon, new CPolyLineHndlr(pCtxt.get(), TKE_Polygon) );
oW3DStreamParser.SetOpcodeHandler( TKE_Polyline, new CPolyLineHndlr(pCtxt.get(), TKE_Polyline) );
oW3DStreamParser.SetOpcodeHandler( TKE_PolyPolyline, new CPolyPolyPntHndlr(pCtxt.get(), TKE_PolyPolyline) );
oW3DStreamParser.SetOpcodeHandler( TKE_Shell, new CShellHndlr(pCtxt.get()) );
oW3DStreamParser.SetOpcodeHandler( TKE_Include_Segment, new CRefSgmtHndlr(pCtxt.get(), TKE_Include_Segment ));
oW3DStreamParser.SetOpcodeHandler( TKE_Style_Segment, new CStylSgmtHndlr(pCtxt.get(), TKE_Style_Segment));
oW3DStreamParser.SetOpcodeHandler( TKE_Modelling_Matrix, new CMtrxHndlr(pCtxt.get(), TKE_Modelling_Matrix ));
oW3DStreamParser.SetOpcodeHandler( TKE_User_Options, new CUserOptnHndlr(pCtxt.get()));
oW3DStreamParser.SetOpcodeHandler( TKE_User_Value, new CUserValHndlr(pCtxt.get()));
oW3DStreamParser.SetOpcodeHandler( TKE_Rendering_Options, new CRndrOptnHndlr(pCtxt.get()));
oW3DStreamParser.SetOpcodeHandler( TKE_Color_RGB, new CClrRGBHndlr(pCtxt.get()));
oW3DStreamParser.SetOpcodeHandler( TKE_Color, new CClrHndlr(pCtxt.get()));
oW3DStreamParser.SetOpcodeHandler( TKE_Color_By_Value, new CClrByValHndlr(pCtxt.get()));
oW3DStreamParser.SetOpcodeHandler( TKE_Color_Map, new CClrMapHndlr(pCtxt.get()));
oW3DStreamParser.SetOpcodeHandler( TKE_PolyCylinder, new CPolyCylHndlr(pCtxt.get()));
oW3DStreamParser.SetOpcodeHandler( TKE_Mesh, new CMeshHndlr(pCtxt.get()));
oW3DStreamParser.SetOpcodeHandler( TKE_LOD, new CLODHndlr(pCtxt.get()));
oW3DStreamParser.SetOpcodeHandler( TKE_Image, new CImgeHndlr(pCtxt.get()));
oW3DStreamParser.SetOpcodeHandler( W3DE_Image, new CW3DImgeHndlr(pCtxt.get()));
oW3DStreamParser.SetOpcodeHandler( TKE_Texture, new CTxtrHndlr(pCtxt.get()));
oW3DStreamParser.SetOpcodeHandler( TKE_Circular_Arc, new CCircHndlr(pCtxt.get(), TKE_Circular_Arc));
oW3DStreamParser.SetOpcodeHandler( TKE_Line, new CLineHndlr(pCtxt.get()));
oW3DStreamParser.SetOpcodeHandler( TKE_NURBS_Curve, new CNurbsCurveHndlr(pCtxt.get()));
oW3DStreamParser.SetOpcodeHandler( TKE_NURBS_Surface, new CNurbsSrfcHndlr(pCtxt.get()));
oW3DStreamParser.SetOpcodeHandler( TKE_Visibility, new CVsblHndlr(pCtxt.get()));
oW3DStreamParser.SetOpcodeHandler( TKE_Rendering_Options, new CRndrOptsHndlr(pCtxt.get()));
oW3DStreamParser.SetOpcodeHandler( TKE_Heuristics, new CHeurHndlr());
oW3DStreamParser.SetOpcodeHandler( TKE_Termination, new CTermHndlr(TKE_Termination));
oW3DStreamParser.SetOpcodeHandler( TKE_Pause, new CTermHndlr(TKE_Pause));
oW3DStreamParser.SetOpcodeHandler( TKE_Clip_Region, new CClipRgnHndlr());
oW3DStreamParser.SetOpcodeHandler( TKE_Tag, new CTestHndlr());

oW3DStreamParser.OpenStream( *pW3DStream );

size_t nBytesRead = 0;
char aBuffer[16384] = {0};
while (pW3DStream->available() > 0) {

nBytesRead = pW3DStream->read( aBuffer, 16384 );
if (oW3DStreamParser.ParseBuffer(aBuffer, (int) nBytesRead, TK_Normal) == TK_Error) {
oW3DStreamParser.CloseStream();
DWFCORE_FREE_OBJECT( pW3DStream );

m_wsLastErr = pwszErrCorruptData;
return false;
}

oW3DStreamParser.CloseStream();

and each of the classes above ie COpenSgmtHndlr looks similar too:

class COpenSgmtHndlr : public TK_Open_Segment {
public:
COpenSgmtHndlr(PstCtxt pCtxt) : CSgmtHndlr(pCtxt), TK_Open_Segment() { ;}
TK_Status Execute( BStreamFileToolkit& parser );
virtual ~COpenSgmtHndlr() {;}
private:
};

and the Execute command gets called for each object that the hoops parses.

Also, if you wish to do texture mapping, you will need to extract them as well, and map them texture/enviornments onto your model as well.

Also Embedded fonts are another thing to extract and get working, but search the forums for this infomration as it is all here.

Anyhow, I hope this helps you.

Cheers
Jason Anderssen
Message 3 of 22
bejn
in reply to: bejn

Jason,

Thank you for the detailed description.

I've started to put together a test application based on your example code. A few questions have come up however:

The variable PstCtxt pCtxt is used in the class COpenSgmtHndlr, but I cannot find it in the API, where is it from?

Another question: The geometry data returned from these functions, are they in a vertex/triangle like format? For OpenGL purposes I need to break everything down to vertices and triangles. Is this what these functions will return, or do they return higher order elements that I have to triangulate my self?

For now I'm going to focus on 3D, and on getting the needed triangles for visualization.

Thanks again for the help.

Reg.
Bjorn
Message 4 of 22
jasona
in reply to: bejn

Bjorn,

The pCtxt variable is my own context variable I use to keep track of the callbacks being fired from the hoops scenegraph, ie, when a OpenSegment has been called, I keep track of this, as another openSegment can be called from inside the first, and I keep track of these. Obvisouly when a closedsegment gets called, and then subtract a opensegment (does this make sense?). So this variable is not required, but something I do.

The geometry data is polypoints for lines and polyline type objects, triangle format for polyhedron, in the case of circles you have to work out your own vertices using a circle algorithm, same with ellipses etc..

However, a nurbs surface (of which I have not found one in a file yet that I have tested) would have to be tesselated yourself. (so if you have a file with one of these, please share this with me, so I can get this working in my 3d engine.)

Cheers
Jason
Message 5 of 22
Anonymous
in reply to: bejn

NURBS:

http://dwf.blogs.com/beyond_the_paper/2006/10/director_of_aut.html

wrote in message news:5485508@discussion.autodesk.com...
Bjorn,

The pCtxt variable is my own context variable I use to keep track of the
callbacks being fired from the hoops scenegraph, ie, when a OpenSegment has
been called, I keep track of this, as another openSegment can be called from
inside the first, and I keep track of these. Obvisouly when a closedsegment
gets called, and then subtract a opensegment (does this make sense?). So
this variable is not required, but something I do.

The geometry data is polypoints for lines and polyline type objects,
triangle format for polyhedron, in the case of circles you have to work out
your own vertices using a circle algorithm, same with ellipses etc..

However, a nurbs surface (of which I have not found one in a file yet that I
have tested) would have to be tesselated yourself. (so if you have a file
with one of these, please share this with me, so I can get this working in
my 3d engine.)

Cheers
Jason
Message 6 of 22
bejn
in reply to: bejn

I managed to retrieve the geometry data that i was hoping for. Although I'm only processing the Shell types for geometry so far, it seems to cover a very large amount of the total geometry in a typical DWF file. Thanks alot for the help with this 🙂
Message 7 of 22
sumannelson
in reply to: bejn

Jason,

At the outset, thanks for this posting. It was very helpful in getting solution to my own issues too.

However, there are some files (like the one attached) where the retrieved geometry seems to be misplaced when I use the mentioned methods. I suspect that it is owing to modeling matrix that needs to be applied to some geometry. I could retrieve the matrices too but i wasn't successful in associating the matrices and the geometry I need to apply it on. Can you kindly throw some light here.

Thanks in advance!

With regards,
Suman
Message 8 of 22
jasona
in reply to: bejn

As a guess, from the dump of the scene graph, shown below,
I would say you have not loaded the library objects ,and then applied the supplied TK_Matrix with the referenced segment after it.

Basically you should load the library into a temp location, then when the "real" scenegraph starts, look up the library entity when the referenced segment is call, and apply the matrix supplied.

Hope this helps, else supply a screen shot of the problem.

Cheers
Jason

TK_Comment

TK_File_Info

TK_Comment

TK_File_Info

TK_Compression

-TK_Open_Segment
(?Style Library/_dwfw3d_PublishedEdges)
-TK_Close_Segment

TK_Bounding

-TK_Open_Segment
(1)
-TK_Tag

-TK_User_Options
(node)
-TK_Heuristics

--TK_Open_Segment
(?Include Library/2)
--TK_Tag

--TK_User_Options
(node)
--TK_Color

---TK_Open_Segment

---TK_Tag

---TK_Color

----TK_Open_Segment

----TK_Tag

-----TK_Open_Segment

-----TK_Tag

-----W3D_Image

-----TK_Texture

-----TK_Close_Segment

----TK_Color

----TK_Shell
(LOD : 0)
----TK_Close_Segment

---TK_Shell
(LOD : 0)
---TK_Close_Segment

---TK_Open_Segment

---TK_Tag

---TK_Referenced_Segment Style
(?Style Library/_dwfw3d_PublishedEdges)
---TK_Referenced_Segment Style

---TK_User_Options
(edges)
---TK_Visibility

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Line

---TK_Circle

---TK_Line

---TK_Circle

---TK_Line

---TK_Circle

---TK_Line

---TK_Circle

---TK_Line

---TK_Circle

---TK_Line

---TK_Circle

---TK_Line

---TK_Circle

---TK_Line

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Line

---TK_Line

---TK_Line

---TK_Line

---TK_Line

---TK_Line

---TK_Line

---TK_Line

---TK_Close_Segment

--TK_Close_Segment

--TK_Open_Segment
(7)
--TK_Tag

--TK_User_Options
(node)
--TK_Matrix

--TK_Referenced_Segment
(?Include Library/2)
--TK_Rendering_Options

---TK_Open_Segment

---TK_Tag

---W3D_Image

---TK_Texture

---TK_Close_Segment

--TK_Color

--TK_Close_Segment

--TK_Open_Segment
(?Include Library/9)
--TK_Tag

--TK_User_Options
(node)
--TK_Color

---TK_Open_Segment

---TK_Tag

---TK_Shell
(LOD : 0)
---TK_Close_Segment

---TK_Open_Segment

---TK_Tag

---TK_Referenced_Segment Style
(?Style Library/_dwfw3d_PublishedEdges)
---TK_Referenced_Segment Style

---TK_User_Options
(edges)
---TK_Visibility

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Close_Segment

--TK_Close_Segment

--TK_Open_Segment
(12)
--TK_Tag

--TK_User_Options
(node)
--TK_Referenced_Segment
(?Include Library/9)
--TK_Rendering_Options

--TK_Color

--TK_Close_Segment

--TK_Open_Segment
(?Include Library/13)
--TK_Tag

--TK_User_Options
(node)
--TK_Color

---TK_Open_Segment

---TK_Tag

---TK_Color

----TK_Open_Segment

----TK_Tag

----TK_Color

----TK_Shell
(LOD : 0)
----TK_Close_Segment

---TK_Shell
(LOD : 0)
---TK_Close_Segment

---TK_Open_Segment

---TK_Tag

---TK_Referenced_Segment Style
(?Style Library/_dwfw3d_PublishedEdges)
---TK_Referenced_Segment Style

---TK_User_Options
(edges)
---TK_Visibility

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Close_Segment

--TK_Close_Segment

--TK_Open_Segment
(17)
--TK_Tag

--TK_User_Options
(node)
--TK_Matrix

--TK_Referenced_Segment
(?Include Library/13)
--TK_Rendering_Options

--TK_Color

--TK_Close_Segment

--TK_Open_Segment
(?Include Library/18)
--TK_Tag

--TK_User_Options
(node)
--TK_Color

---TK_Open_Segment

---TK_Tag

---TK_Color

---TK_Shell
(LOD : 0)
---TK_Close_Segment

---TK_Open_Segment

---TK_Tag

---TK_Referenced_Segment Style
(?Style Library/_dwfw3d_PublishedEdges)
---TK_Referenced_Segment Style

---TK_User_Options
(edges)
---TK_Visibility

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Circle

---TK_Close_Segment

--TK_Close_Segment

--TK_Open_Segment
(21)
--TK_Tag

--TK_User_Options
(node)
--TK_Matrix

--TK_Referenced_Segment
(?Include Library/18)
--TK_Close_Segment

--TK_Open_Segment
(22)
--TK_Tag

--TK_User_Options
(node)
---TK_Open_Segment
(?Include Library/23)
---TK_Tag

---TK_User_Options
(node)
---TK_Color

----TK_Open_Segment

----TK_Tag

----TK_Shell
(LOD : 0)
----TK_Close_Segment

----TK_Open_Segment

----TK_Tag

----TK_Referenced_Segment Style
(?Style Library/_dwfw3d_PublishedEdges)
----TK_Referenced_Segment Style

----TK_User_Options
(edges)
----TK_Visibility

----TK_Line

----TK_NURBS_Curve

----TK_Line

----TK_Circle

----TK_Line

----TK_Line

----TK_Line

----TK_Circle

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Circle

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Circle

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Close_Segment

---TK_Close_Segment

---TK_Open_Segment
(26)
---TK_Tag

---TK_User_Options
(node)
---TK_Referenced_Segment
(?Include Library/23)
---TK_Close_Segment

---TK_Open_Segment
(?Include Library/27)
---TK_Tag

---TK_User_Options
(node)
---TK_Color

----TK_Open_Segment

----TK_Tag

----TK_Color

----TK_Shell
(LOD : 0)
----TK_Close_Segment

----TK_Open_Segment

----TK_Tag

----TK_Referenced_Segment Style
(?Style Library/_dwfw3d_PublishedEdges)
----TK_Referenced_Segment Style

----TK_User_Options
(edges)
----TK_Visibility

----TK_Circle

----TK_Line

----TK_Circle

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Circle

----TK_Line

----TK_Circle

----TK_Line

----TK_Circle

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Circle

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Line

----TK_Close_Segment

---TK_Close_Segment

---TK_Open_Segment
(30)
---TK_Tag

---TK_User_Options
(node)
---TK_Matrix

---TK_Referenced_Segment
(?Include Library/27)
---TK_Close_Segment

---TK_Open_Segment
(31)
---TK_Tag

---TK_User_Options
(node)
---TK_Matrix

---TK_Referenced_Segment
(?Include Library/27)
---TK_Close_Segment

---TK_Open_Segment
(32)
---TK_Tag

---TK_User_Options
(node)
---TK_Matrix

---TK_Referenced_Segment
(?Include Library/27)
---TK_Close_Segment

--TK_Close_Segment

-TK_Close_Segment

TK_Compression
Message 9 of 22
sumannelson
in reply to: bejn

Thank you for the prompt reply. I think the geometry is coming out correctly now.

Two more questions:
1. Is there a uniform way of extracting texture data in RGB format, irrespective of whether texture is embedded or external.
2. I am using Autodesk DWF viewer to compare the exported models from my exporter with the original DWF. In the viewer, I see the model tree (assembly or parts at the roots with composed parts and other assemblies as leaves, recursively) in the "model" left pane. The names that are used for each shell in the model tree do not appear anywhere in the model while parsing the DWF file's 3D graphic resources - I can only see strings like "?Include Library/2" on the shells. Am I missing something?

Please let me hear back.

Thanks in advance,
Suman
Message 10 of 22
jasona
in reply to: bejn

See the Object Defination information in the toolkit. Basically you must read all the object definations before parsing the hoops scenegraph.
Then you just simply marry them up.
The relationship is in the OpenSegment handler, simply marry the name of the Segment to the name of the ObjectInstance.

You should be able to get all the information you require.

Cheers
Jason Anderssen
Message 11 of 22
sumannelson
in reply to: bejn

Oh! I will try that.

Thank you very much!
Suman
Message 12 of 22
chandru.pachai
in reply to: bejn

So the code realy helped me a lot in understanding DWF implementation.

please Show me the examples of implementation of all the callback classes for different objects in dwf.

my requirements is simply i have write all the geometric properties and other physical properties(like color, line pattern, fill details etc...) into a XML or txt file.

please can any one help me out. how i can explore the geometry data for the polyline, polygon, circle etc.. using code samples.

how i could implement the execute functions for different objects with sample for callbacks set to SetOpcodeHandler.

i have used similar kind of approach for exploring the W3d files.

when i view the dwf file in the viewer. i found lot of poly lines, but while debuging its not executing the callbacks in the polyline class.

please send some code from which i understand them...

Thanks in Advance
Chandru.P
Message 13 of 22
jasona
in reply to: bejn

Following is some code I quickly put together to help you understand.

I have made the simple example print to a opengl context, but you must decide on how you want to best use the data, ie opengl, directx, database storage, calcualation, scenegraph storage etc....

As for all the other types of handlers, you simply read the hoops documentation for all the gory bits and read through the header files on how you should parse them.

Hope this helps
Jason Anderssen

TK_Status CPolyLineHndlr::Execute( BStreamFileToolkit &parser) {
TK_Status status = TK_Polypoint::Execute(parser);
if (status != TK_Normal){
return status;
}

glBegin(GL_LINE_STRIP);
for( int i = 0; i < m_count; i++ ) {
glVertex3d(m_points[i * 3], m_points[i*3+1], m_points[i*3+2]);
}
glEnd();

return status;

}
Message 14 of 22
chandru.pachai
in reply to: bejn

thanks yaar. I will study and if i have any problem. i will get back to you.

My application is just to read all the geometric data and object properties of each object and put them in organised XML file.

i don't realy need to work on any thing else.

there where i am struck. can u help me in reading all the geometric and other properties of different objects like line, poly line, polygon, circle...

I have wriitten the my application in which i obtained the 3d stream and implemented all the class and setopcodehandler, but i am struck with reading the geomentic properties of each objects. (how i should go head in customizing the classes). i didn't find any help on the web.

i realy not needed to work with the obtained data. the XML file will serve as a input for other software.

my xml will have oly properties like color, points, line pattern, block details.

i use autocad to export the 3d dwf.

could u help me with some code sample...

Thanks and regards,
Chandru.P
Message 15 of 22
jasona
in reply to: bejn

I would seriously re-consider xml'ing the file, as you will end up with a huge file in the case of very large drawings.

eg, if a library object, that consists of 300 different objects, is pasted 300 different times, you will have to either make your file 300 * 300 times bigger, or re-do what autocad has already designed to be an effecient method.

Anyhow, if you would like any assistance with your code, email me at janderssen@gmail.com and I will try and assist where I can. I wont help with algorithms like how to draw a circle etc. you have to figure this stuff out yourself, but I will help where I deem it a bit difficult to understand.

Cheers
Jason Anderssen
Message 16 of 22
chandru.pachai
in reply to: bejn

Yes I understand that it result in huge file. but the requirement is in such way.

i have read only the existing objects property.

i have nothing to create with DWF. i have to explore all object properties.

thanx,
Chandru.p
Message 17 of 22
chandru.pachai
in reply to: bejn

Hi,

I have small proplem in getting the polyline points. that
on calling the m_pW2DStrm->process_next_object();
it goes to the callback function of poly line where i retrive the points it give the junk values as follows
Number of Points = 5
X0 = 2147475881 Y0 = 3540
X1 = 2147476920 Y1 = 3540
X2 = 2147476920 Y2 = 4201
X3 = 2147475881 Y3 = 4201
X4 = 2147475881 Y4 = 3540

The code i used for getting the values is
WT_Result CWhipHndlr::prcsPolyLine ( WT_Polyline &pPolyline, WT_File & file )
{
WT_Result res = WT_Result::Unknown_File_Read_Error;
if (m_pDwf2DStrm)
{
fout<<""< int color_index = file.rendition().color().index();
WT_RGBA32 fdf = file.rendition().color().rgba();
fout<<"\t\tColor Index = \""<<<"\"\tRed = \""<<(int)fdf.m_rgb.r<<"\"\t Blue = \""<<(int)fdf.m_rgb.b<<"\"\t Green = \""<<(int)fdf.m_rgb.g<<"\"\t Alpha = \""<<(int)fdf.m_rgb.a<<"\""< int iCount = pPolyline.count();
fout<<"\t\t\tNumber of Points = "< WT_Logical_Point *pPoints = new WT_Logical_Point();
pPoints=pPolyline.points();
for(int i =0;i {
fout<<"\t\t\t\tX"<<<" = "<.m_x<<"\t Y"<<<" = "<.m_y< }
fout<<"
"<<"\t\t";
res = WT_Result::Success;
}


if u see other values are correct.

onthing i noticed on debugging instead of calling the Process m_pW2DStrm->process_next_object(); if i call the m_pW2DStrm->get_next_object(); and using the following code in the switch case

case WT_Object::Polyline_ID:
{fout<<"Polyline_ID"< WT_File pFile;
WT_Polyline* pPoly = (WT_Polyline*) pObj;
fout<<"\t\t\tNumber of Points = "<count()<points();
for(int i =0;icount();i++)
{
fout<<"\t\t\tX"<<<" = "<.m_x<<"\t Y"<<<" = "<.m_y< }
break;}
return res;
}

i get the correct values as follows
Number of Points = 5
X0 = -1039 Y0 = -661
X1 = 0 Y1 = -661
X2 = 0 Y2 = 0
X3 = -1039 Y3 = 0
X4 = -1039 Y4 = -661

Can u Help me so that i use the call back way of approaching the Objects please... I am not able to find the mistake i have comitted.

Thanks in Advance
Chandru.P
Message 18 of 22
chandru.pachai
in reply to: bejn

Hi,

I have small proplem in getting the polyline points. that
on calling the m_pW2DStrm->process_next_object();
it goes to the callback function of poly line where i retrive the points it give the junk values as follows
Number of Points = 5
X0 = 2147475881 Y0 = 3540
X1 = 2147476920 Y1 = 3540
X2 = 2147476920 Y2 = 4201
X3 = 2147475881 Y3 = 4201
X4 = 2147475881 Y4 = 3540

The code i used for getting the values is
WT_Result CWhipHndlr::prcsPolyLine ( WT_Polyline &pPolyline, WT_File & file )
{
WT_Result res = WT_Result::Unknown_File_Read_Error;
if (m_pDwf2DStrm)
{
fout<<""< int color_index = file.rendition().color().index();
WT_RGBA32 fdf = file.rendition().color().rgba();
fout<<"\t\tColor Index = \""<<<"\"\tRed = \""<<(int)fdf.m_rgb.r<<"\"\t Blue = \""<<(int)fdf.m_rgb.b<<"\"\t Green = \""<<(int)fdf.m_rgb.g<<"\"\t Alpha = \""<<(int)fdf.m_rgb.a<<"\""< int iCount = pPolyline.count();
fout<<"\t\t\tNumber of Points = "< WT_Logical_Point *pPoints = new WT_Logical_Point();
pPoints=pPolyline.points();
for(int i =0;i {
fout<<"\t\t\t\tX"<<<" = "<.m_x<<"\t Y"<<<" = "<.m_y< }
fout<<"
"<<"\t\t";
res = WT_Result::Success;
}


if u see other values are correct.

onthing i noticed on debugging instead of calling the Process m_pW2DStrm->process_next_object(); if i call the m_pW2DStrm->get_next_object(); and using the following code in the switch case

case WT_Object::Polyline_ID:
{fout<<"Polyline_ID"< WT_File pFile;
WT_Polyline* pPoly = (WT_Polyline*) pObj;
fout<<"\t\t\tNumber of Points = "<count()<points();
for(int i =0;icount();i++)
{
fout<<"\t\t\tX"<<<" = "<.m_x<<"\t Y"<<<" = "<.m_y< }
break;}
return res;
}

i get the correct values as follows
Number of Points = 5
X0 = -1039 Y0 = -661
X1 = 0 Y1 = -661
X2 = 0 Y2 = 0
X3 = -1039 Y3 = 0
X4 = -1039 Y4 = -661

Can u Help me so that i use the call back way of approaching the Objects please... I am not able to find the mistake i have comitted.

Thanks in Advance
Chandru.P
Message 19 of 22
Anonymous
in reply to: bejn

X0 = 2147475881 Y0 = 3540

The coordinates look perfectly fine to me. These are Whip coordinates which
can range from anywhere between MIN_INT to MAX_INT. For some obscure reason
AutoCAD always generates DWF coordinates with the X-value very close to
MAX_INT.
You have to use a units.transform function to translate the coordinates back
to the original AutoCAD DWG coordinates. Before doing that there is no way
to tell if the coordinates are 'junk'.

Jos Groot Lipman
Message 20 of 22
chandru.pachai
in reply to: bejn

One thing i noticed on debugging instead of calling the Process m_pW2DStrm->process_next_object(); if i call the m_pW2DStrm->get_next_object(); and using the following code in the switch case

case WT_Object::Polyline_ID:
{fout<<"Polyline_ID"< WT_File pFile;
WT_Polyline* pPoly = (WT_Polyline*) pObj;
fout<<"\t\t\tNumber of Points = "<count()<points();
for(int i =0;icount();i++)
{
fout<<"\t\t\tX"<<<" = "<.m_x<<"\t Y"<<<" = "<.m_y< }
break;}
return res;
}

i get the correct values as follows
Number of Points = 5
X0 = -1039 Y0 = -661
X1 = 0 Y1 = -661
X2 = 0 Y2 = 0
X3 = -1039 Y3 = 0
X4 = -1039 Y4 = -661

Can u Help me so that i use the call back way of approaching the Objects please... I am not able to find the mistake i have comitted.

Thanks in Advance
Chandru.P

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

”Boost

 

”Tips

 

”Services