Editing Geometry Viewer Application for BRL-CAD

From BRL-CAD

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 10: Line 10:
 
== Outline ==
 
== Outline ==
  
The idea is to build a geometry viewer application that generates a standalone double-clickable file that views a given model. The approach is to concatenate the contents of a given “.g” file with the function calls from librt and display a “.g” file, in a standard brlcad setup.
+
The idea is to build a geometry viewer application that generates a standalone double-clickable file that views a given model. The approach is to concatenate the contents of a given “.g” file with the function calls from librt, libdm that parse and display a “.g” file, in a standard brlcad setup.
  
 
Our source code will generate an executable, we will then separately concatenate a ".g" file into this executable:
 
Our source code will generate an executable, we will then separately concatenate a ".g" file into this executable:
Line 18: Line 18:
 
# Finding the start of ".g" file bytes/headers
 
# Finding the start of ".g" file bytes/headers
 
# Populating the g file database for librt
 
# Populating the g file database for librt
# Plotting the items in the g file using [http://www.glfw.org/docs/latest/pages.html glfw3].
+
# Pass this onto libdm for creation
  
  
 
Our motivation is to introduce portability and ability to share results of brlcad via email with users who don’t have brlcad setup in their environments. First we will develop a standalone application but later this can be integrated into mged or any other tool as a brlcad feature.
 
Our motivation is to introduce portability and ability to share results of brlcad via email with users who don’t have brlcad setup in their environments. First we will develop a standalone application but later this can be integrated into mged or any other tool as a brlcad feature.
  
== Status (15.08.2016) ==
+
== Status (22.03.2016) ==
 +
 
 +
Our source code takes a .g file as input and stores it into a buffer. It can also pass this file to librt and populate the db_i structure. Currently we are trying to interface it with libdm.
 +
 
  
Our source code takes an embedded .g file and locates it's header bytes from there on it calls db_open() by writing the gbytes into a temporary file and populates struct db_i. The source also calls db_ls to get a count of objects in the database and calls db_walk_tree on one of the objects. Then work a list of all top level objects is fetched via db_ls and then db_walk_tree is called on each of them. The next step is to plot these zones, for this purpose we have decided to choose [http://www.glfw.org/docs/latest/pages.html glfw3]. Currently the work is being done to generate a simple window from our application using glfw.
 
 
== Task Breakdown ==
 
== Task Breakdown ==
  
Line 37: Line 39:
 
• [http://brlcad.org/docs/doxygen-r64112/d4/de4/group__libdm.xhtml '''Libdm'''] is BRL-CAD's primary graphics display manager (dm) library. It is used to display geometry in GUI. This will be utilized by our source to visualize model files.
 
• [http://brlcad.org/docs/doxygen-r64112/d4/de4/group__libdm.xhtml '''Libdm'''] is BRL-CAD's primary graphics display manager (dm) library. It is used to display geometry in GUI. This will be utilized by our source to visualize model files.
  
This resulting draw result will then be bundled into an executable (Linux) and later into packages for Mac & Windows.
+
This resulting draw result will then be bundled into an “.exe” (windows) and later into packages for Mac & Linux.
  
 
== Task list ==
 
== Task list ==
Line 43: Line 45:
 
; 1. Evaluate technology to be used
 
; 1. Evaluate technology to be used
 
* <s>Develop initial project design draft</s> [DONE]
 
* <s>Develop initial project design draft</s> [DONE]
* <s>Setup development environment</s> [DONE]
+
* Setup development environment
  
 
** ''' Installing BRLCAD:''' ([http://svn.code.sf.net/p/brlcad/code/brlcad/trunk/INSTALL '''Install Instructions'''])
 
** ''' Installing BRLCAD:''' ([http://svn.code.sf.net/p/brlcad/code/brlcad/trunk/INSTALL '''Install Instructions'''])
Line 108: Line 110:
 
** Getting a file descriptor of bytes in memory and passing it on to [http://brlcad.org/docs/doxygen-r64112/d3/d9b/group__dbio.xhtml#gaa9eb8edb99fa1da5d188587e07d8dacc '''db_open'''].
 
** Getting a file descriptor of bytes in memory and passing it on to [http://brlcad.org/docs/doxygen-r64112/d3/d9b/group__dbio.xhtml#gaa9eb8edb99fa1da5d188587e07d8dacc '''db_open'''].
  
; 4. Create application Interface with librt
+
; 4. Create application interface to brlcad libraries [http://brlcad.org/w/images/3/3d/Application_Development.pdf]
 +
* Interface with librt
 
Librt is used to open brlcad geometry files and edit them. It reads a .g file by calling the function [http://brlcad.org/docs/doxygen-r64112/d3/d9b/group__dbio.xhtml#gaa9eb8edb99fa1da5d188587e07d8dacc '''db_open'''] and populates a [http://brlcad.org/docs/doxygen-r64112/d2/d66/structdb__i.xhtml '''db_i structure''' ]. To view the geometry files we need [http://brlcad.org/docs/doxygen-r64112/d4/de4/group__libdm.xhtml '''Libdm'''] which takes this db_i structure as input to do so.
 
Librt is used to open brlcad geometry files and edit them. It reads a .g file by calling the function [http://brlcad.org/docs/doxygen-r64112/d3/d9b/group__dbio.xhtml#gaa9eb8edb99fa1da5d188587e07d8dacc '''db_open'''] and populates a [http://brlcad.org/docs/doxygen-r64112/d2/d66/structdb__i.xhtml '''db_i structure''' ]. To view the geometry files we need [http://brlcad.org/docs/doxygen-r64112/d4/de4/group__libdm.xhtml '''Libdm'''] which takes this db_i structure as input to do so.
  
As we have located the g file bytes, we simply write out these bytes onto a temporary file and pass this file onto db_open(). db_open then populates the database structure db_i. An [http://brlcad.org/wiki/Example_db_walk_tree '''example'''] is already available that shows the usage of db_open. We are utilizing the skeleton of this example to populate the struct db_i. A cleaner approach would be to directly populate the struct db_i and I am working on that.
+
This [https://github.com/asadpiz/brlcad-viewer/commit/b9e083dc59408354c7194b3c36525fe5e9d80eed '''commit'''] takes a .g file and calls the db_open function from within the viewer application. Right now it just prints out a single value from the populated structure.
 +
 
 +
An [http://brlcad.org/wiki/Example_db_walk_tree '''example'''] is already available that shows the usage of db_open. We are utilizing the skeleton of this example to populate the struct db_i.
 +
 
 +
* Interface with libdm
 +
Interfacing with librt was aided by the hello_world example but interfacing librt was a bit more tricky due to lack of resources. To find out the function calls, dependencies and call graph of "mged->libdm" I used profiling tools and printfs. Currently I have understood the basic architecture of the interaction:
 +
 
 +
[[Image:ClusterCallby-libdm.png|396px|center|libdm interactions with mged]]
  
The next step is to identify the top level objects of a g file. These can be listed by issuing a [http://brlcad.org/wiki/MGED_CMD_tops "tops"] command on mged after opening a g file. In code this can be achieved by following db_ls and/or DB_LS_TOPS in src/libged/*.c.
 
  
After these top level objects have been identified we need to call [http://brlcad.sourceforge.net/doxygen/d3/d9b/group__dbio.html#ge69d8a8eb90d514e554e1b84bbb7018f db_walk_tree] on each of them.
+
Now I am in the process of figuring out which calls are required by my application source.
 +
; 4. Create application interface with model file:
 +
* Create input interface to parse “.g” file
  
;5 Plot the Model using GLFW
 
  
GLFW is basically a library to use with OpenGL, to aid in the creation of graphical windows and some other stuff. The plan is to use this library to open up a simple window and then plot all the members of the g file into this window.  
+
The [https://github.com/asadpiz/brlcad-viewer/commit/f064ad3bdb37bbfd0d9f982c73891bbe47724d8d '''commit'''], simply reads a file into a buffer and prints out its contents. Our interest is in the header bits of the file i.e., the bits that start with 7601...., these will help us identify the start of a ".g" file later.
  
; 6. Develop front end
+
* Create output interface to parse output from libdm.
 +
; 5. Develop front end
 
* Develop Single window view
 
* Develop Single window view
 
* Develop File Input
 
* Develop File Input
; 7. Write Functional testing test cases.
+
; 6. Write Functional testing test cases.
  
 
== Project Workflow ==
 
== Project Workflow ==

Please note that all contributions to BRL-CAD may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see BRL-CAD:Copyrights for details). Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)