Fct_Contour_Create

 

Compute all the contours for a specific frame.

 

 

Syntax

 

int  Fct_Contour_Create(

          SliceO_Frame * frame

          unsigned int mode,

          unsigned short o_x,

          unsigned short o_y

) ;

 

 

Parameters

 

frame

Pointer to the frame to compute.

 

mode

          Control the formation of the contour loops.

 

SHELL_MODE_LOOP

If the TAG values are on the border of the frame, the loop will be closed, otherwise it will stay open.

 

SHELL_MODE_INSIDE

Place a border between a TAG and a TAG value that is greater than it.

 

SHELL_MODE_OUTSIDE

Place a border betweena TAG value and a TAG value that is smaller than it.

 

o_x, o_y

Sub-sampling in horizontal and vertical direction. 1 mean no sub-sampling (each pixel is used).

 

 

Return value

 

This function return 0 if the function failed.

 

 

Remarks

 

 

 

 

Requirements

 

Header:

          sliceO_include.hpp

 

 

Library:

          sliceO_Structures.lib

 

 

 

Example

 

Computing the "Snake From TAG" in the "Snake" module.  The snakes will be derived from a 2x2 sub-sampling contour.

 

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

//

//          Snake_From_TAG

//

//          Param:          (void)

//

//          Return:          (int)          NULL if error

//

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

int          Snake_From_TAG( void )

{

          Snake_Mode = 2 ;

 

          unsigned short          TAG_Nb =   (unsigned short)  Fct_Variable_Value( "$TAG_NB" ) ;

          int *pts_tot = new int [TAG_Nb] ;

          memset( (void *) pts_tot, NULL, TAG_Nb * sizeof(int) ) ;

 

          // --- for each selected image ---

          if ( ! Iterator_Init( ITERATOR_2, "Snake_From_TAG" ) )

              return( 0 ) ;

 

          // ================================================================

          // --- no updates until we are done

          // ================================================================

          Fct_Update( UPDATE_DELAY_ON ) ;

          SET_CURS_WAIT ;

 

          while( SliceO_Frame *frame = (SliceO_Frame *) Iterator_Class( ITERATOR_2, CLASS_ID_FRAME, NULL, ITER_FLAG_SELECT ) ) {

 

                    // --- clear the present Snake values ---

                    for ( int i=0; i < Snake_Nb; i++ )

                              if ( Snake_List[i]->frame == frame )

                                        Snake_Remove( Snake_List[i] ) ;

 

                    // --- compute a new contour with 2x2 oversampling ---

                    Fct_Contour_Create( frame, SHELL_MODE_LOOP | SHELL_MODE_BORDER, 2, 2 ) ;

 

                    // --- information stool ---

                    for ( unsigned char tag=1; tag < TAG_Nb; tag++ ) {

 

                              // --- Get the contour points for this tag and this frame ---

                              Point_2D *pts ;

                              int pts_nb = Fct_Contour_Get_Pts( frame, tag, &pts ) ;

 

                              if ( ! pts_nb )

                                        continue ;

 

                              pts_tot[tag] += pts_nb ;

 

                              // --- now get the connectivity for these points ---

                              SliceO_Buffer *loop_pt ;

                              int loop_nb = Fct_Contour_Get_Loops( frame, tag, &loop_pt ) ;

 

                              for ( int j=0; j < loop_nb; j++ ) {

 

                                        int  loop_pts_nb = loop_pt[j].Size_Get() / sizeof(int) ;

                                        int *loop_pts_id = (int *) loop_pt[j].Data_Get() ;

 

                                        // --- we need a minimum of points on the contour ---

                                        if ( loop_pts_nb <= MIN_NB_PTS )

                                                  continue ;

 

                                        // --- create a new snake ---

                                        Snakes *snake = new Snakes ;

                                        snake->Create( frame, tag ) ;

 

                                        // --- add the new points ---

                                        snake->nb_points = loop_pts_nb ;

                                        MALLOC( Snake_Points *, snake->point, loop_pts_nb, sizeof(Snake_Points) ) ;

 

                                        for ( int i=0; i < loop_pts_nb; i++ ) {

                                                  int index = loop_pts_id[i] ;

                                                  // --- insert new point ---

                                                  snake->point[i].radius = DEFAULT_RADIUS ;

                                                  snake->point[i].fx = pts[index].x + 0.5f ;

                                                  snake->point[i].fy = pts[index].y + 0.5f ;

                                                  snake->point[i].flag = REPARAM | RESNAKE | REFILTER ;

                                        }

                                        snake->creation = 0 ;

                                        snake->flag = REPARAM | RESNAKE | REFILTER ;

 

                                        // --- compute the Bounding box ---

                                        snake->Compute_Bounding_Box() ;

 

                                        Snake_Add( snake ) ;

                              }

                    }

 

                    // --- reset the lists ---

                    Fct_Contour_Free( frame ) ;

          }

          Iterator_End( ITERATOR_2 ) ;

 

          for ( unsigned char tag=1; tag < TAG_Nb; tag++ )

                    if ( pts_tot[tag] )

                              Error_Fct( hwnd, ERROR_CODE_REPORT, "\tTAG[\001%d\002]: \001%d \002points on contours", tag, pts_tot[tag] ) ;

 

          delete [] pts_tot ;

 

          // ================================================================

          // --- now we can restart the updates ---

          // ================================================================

          Fct_Update( UPDATE_DELAY_OFF ) ;

 

          RESET_CURS ;

 

          // --- redraw the image ---

          Fct_Redraw( REDRAW_DB_OPENGL ) ;

 

          return( 1 ) ;

}

 

See also

 

Fct_Contour_Compute

Fct_Contour_Free