K3D Online Documentation

Daniel Macek <xmacekd@kers.fsv.cvut.cz>
Ondra Hrstka <ondra@klobouk.fsv.cvut.cz>


K3D is a C++ class that is able to display 3d data into KRESLITKO.
It stores a database of nodes and edges - these items are set using functions 'node' and 'edge'. On 'draw' function call it displays them into KRESLITKO using linear perspective. Parameters of the linear perspective can be set using functions 'set_angle', 'set_translation' and 'set_viewpoint'. Picture will be displayed into window that is set by 'set_window'.

There is also a method 'process_function' that can process a 3d-function graph into K3D database included in k3d lilbrary.

It is build up automatically with KRESLITKO itself. To use it, simply include k3d.h into your source code.


Function reference:

   k3d ( int opb=1024 , int oph=1024 ) ;

                a constructor; parameter 'opb' means maximal number of nodes and 'oph' maximal number of edges

  ~k3d ( void ) ;

                a destructor

   void k3d::node ( double ox , double oy , double oz , int oi ) ;

                sets an 'oi'-th node to coordinates ('ox','oy','oz')

   void k3d::edge ( int oa , int ob , int oi ) ;

                sets an 'oi'-th edge to start at node number 'oa' and end at node number 'ob'

   void k3d::rotate ( double oo , double &or , double &ot ) ;

        internal function that rotates polar coordinates 'or' and 'ot' by an angle 'oo'

   void k3d::set_angle ( double ox , double oy , double oz ) ;

                rotates whole model sequentially: 1) by 'oz' round z-axe, 2) by 'oy' round y-axe, 3) by 'oz' round x-axe; angles are given in degrees (note: k3d holds original and transformed database, so if you use this function several times, it does not add one rotation to another, but everytime starts from given model)

   void k3d::set_translation ( double odx , double ody , double odz ) ;

                translates model by 'odx' in x-direction and so on (note: k3d holds original and transformed database, so if you use this function several times, it does not add one rotation to another, but everytime starts from given model) 

   void k3d::set_viewpoint ( double opx , double opy , double opz ) ;

                sets a viewpoint of linear perspective to point ('opx','opy','opx')

   void k3d::set_window ( double ox1 , double oy1 , double ox2 , double oy2 ) ;

                sets a window inside viewport of KRESLITKO to which the image will be plotted

   void k3d::draw ( kreslitko *ok ) ;

                draws a picture

   void process_function ( double ( *ofunction )( double,double  ) , double oxmin , double oxmax , double oymin , double oymax , int oxs , int oys , k3d *ow )

                processes a 3d-function graph into k3d database; function itself is given by a pointer 'ofunction', 'oxmin','oxmax','oymin','oymax' are limits of a processed domain, 'oxs' and 'oys' is a division and 'ow' is a k3d class (see 'example9.c' in examples directory)


Let's see an example of using this class (library). This program (is also included in 'examples' directory as 'example8.c') reads nodes from 'example8.nodes.dat' and edges

#include <stdio.h>
#include <kreslitko.h>
#include <k3d.h>

void main ( void )
{
    k3d w( 8,12 ) ;
    FILE *f;
    FILE *g;
    f=fopen( "example8.nodes.dat","rt" ) ;
    g=fopen( "example8.edges.dat","rt" ) ;
    double x,y,z ;
    int i,j ;
    for( i=0 ; i<8 ; i++ )
    {
        fscanf( f,"%lf",&x ) ;
        fscanf( f,"%lf",&y ) ;
        fscanf( f,"%lf",&z ) ;
        w.node( x,y,z,i ) ;
    }
    int a,b;
    for( j=0 ; j<12 ; j++ )
    {
        fscanf( g,"%d",&a ) ;
        fscanf( g,"%d",&b ) ;
        w.edge( a,b,j ) ;
    }
    fclose( f ) ;
    fclose( g ) ;

    w.set_angle( 50.0,30.0,25.0 ) ;
    w.set_translation( 0.0,5.0,0.0 ) ;

    kreslitko k ;
    k.create_button( "Close",55 ) ;
    k.open_graphics( -10.0,-10.0,10.0,10.0,400,400 ) ;

    w.set_viewpoint( 0.0,-20.0,0.0 ) ;
    w.set_window( -2.0,-2.0,6.0,6.0 ) ;

    w.draw( &k ) ;

    k.wait_for_signal( 55 ) ;
}


Example program above generates this picture: