Vertices.c

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------*/
00002 /* file: Vertices.h                                                       */
00003 /* Copyright INRIA 2006                                                   */
00004 /* Authors : Jean-Baptiste Silvy                                          */
00005 /* desc : Contains functions to store vertices for the zoom               */
00006 /*------------------------------------------------------------------------*/
00007 
00008 #include "Vertices.h"
00009 #include "MALLOC.h"
00010 #include "GetProperty.h"
00011 #include "GraphicZoom.h"
00012 #include "sciprint.h"
00013 
00014 static int vertex_index = 0 ;
00015 static Vertices * pHead  = NULL ;
00016 static Vertices * pHead2 = NULL ;
00017 
00018 /*--------------------------------------------------------------------------------------------------*/
00019 int  getVertexIndex( void )
00020 {
00021   return vertex_index ;
00022 }
00023 /*--------------------------------------------------------------------------------------------------*/
00024 void setVertexIndex( int ind )
00025 {
00026   vertex_index = ind ;
00027 }
00028 /*--------------------------------------------------------------------------------------------------*/
00029 int SetMinMaxVertices(Vertices *vertices_list, double *xmin, double *ymin, double *zmin,double *xmax, double *ymax, double *zmax)
00030 { 
00031   Vertices * pCurrent = vertices_list;
00032 
00033   *xmin = *xmax = vertices_list->value_x;
00034   *ymin = *ymax = vertices_list->value_y;
00035   *zmin = *zmax = vertices_list->value_z;
00036 
00037   while (pCurrent != NULL) {
00038     if(pCurrent->value_x >  *xmin) *xmin = pCurrent->value_x;
00039     if(pCurrent->value_y >  *ymin) *ymin = pCurrent->value_y;
00040     if(pCurrent->value_z >  *zmin) *zmin = pCurrent->value_z;
00041 
00042     if(pCurrent->value_x <  *xmax) *xmax = pCurrent->value_x;
00043     if(pCurrent->value_y <  *ymax) *ymax = pCurrent->value_y;
00044     if(pCurrent->value_z <  *zmax) *zmax = pCurrent->value_z;
00045 
00046     pCurrent = pCurrent->pNext;
00047   }
00048 
00049   return 0;
00050 }
00051 /*--------------------------------------------------------------------------------------------------*/
00052 int GetVerticesAt(Vertices *vertices_list, int *xm, int *ym, double *x, double *y, double *z)
00053 {
00054   Vertices * pCurrent = vertices_list;
00055 
00056   if(pHead2 == (Vertices *) NULL)
00057     pHead2 = pCurrent;
00058 
00059   *xm = pHead2->value_xm;
00060   *ym = pHead2->value_ym;
00061   *x  = pHead2->value_x;
00062   *y  = pHead2->value_y;
00063   *z  = pHead2->value_z;
00064 
00065   pHead2 = pHead2->pNext;
00066 
00067   return 0;
00068 }
00069 /*--------------------------------------------------------------------------------------------------*/
00070 int RemoveNext(Vertices *pCurrent)
00071 {
00072   Vertices * DeletedElement = pCurrent->pNext;
00073   Vertices * pNextNext =  pCurrent->pNext->pNext;
00074 
00075   FREE(DeletedElement); DeletedElement = (Vertices *) NULL;
00076 
00077   pCurrent->pNext = pNextNext;
00078 
00079   return 0;
00080 }
00081 /*--------------------------------------------------------------------------------------------------*/
00082 int FreeVertices(sciPointObj * psubwin)
00083 {
00084   sciSubWindow * ppsubwin = pSUBWIN_FEATURE(psubwin);
00085   Vertices * pCurrent = ppsubwin->vertices_list;
00086 
00087   if (pCurrent != NULL) {
00088 
00089     /*pCurrent = Tete; */
00090     while (pCurrent->pNext != NULL){
00091       RemoveNext(pCurrent);
00092     }
00093     FREE(ppsubwin->vertices_list); ppsubwin->vertices_list = (Vertices *) NULL;
00094   }
00095 
00096   pHead = (Vertices *) NULL;
00097   pHead2 = (Vertices *) NULL;
00098 
00099   return 0;
00100 }
00101 /*--------------------------------------------------------------------------------------------------*/
00102 /* Vertices * Tete = NULL; */
00103 
00104 int Store3DPixelValues(sciPointObj * pobj, int xm, int ym, double x, double y, double z)
00105 {
00106 
00107   sciPointObj * psubwin = sciGetParentSubwin(pobj);
00108   sciSubWindow *ppsubwin = pSUBWIN_FEATURE(psubwin);
00109 
00110   if( isZoom3dOn() )
00111   {
00112     Vertices * pCurrent = ppsubwin->vertices_list;
00113 
00114     if (pCurrent != NULL) {
00115 
00116       pCurrent = pHead;
00117 
00118       if(( pCurrent->pNext = (Vertices*) MALLOC(sizeof(Vertices))) == NULL){
00119         sciprint("Allocation failed for vertices when zoom called.\n");
00120         return -1;
00121       }
00122 
00123       pCurrent->pNext->pNext = NULL;
00124 
00125       pCurrent->pNext->value_xm = xm;
00126       pCurrent->pNext->value_ym = ym;
00127       pCurrent->pNext->value_x = x;
00128       pCurrent->pNext->value_y = y;
00129       pCurrent->pNext->value_z = z;
00130 
00131       pHead = pCurrent->pNext;
00132 
00133     }
00134     else
00135     { /* first element is created */
00136       if((ppsubwin->vertices_list = (Vertices*) MALLOC(sizeof(Vertices))) == NULL){
00137         sciprint("Allocation failed for vertices when zoom called\n");
00138         return -1;
00139       }
00140 
00141       ppsubwin->vertices_list->value_xm = xm;
00142       ppsubwin->vertices_list->value_ym = ym;
00143       ppsubwin->vertices_list->value_x = x;
00144       ppsubwin->vertices_list->value_y = y;
00145       ppsubwin->vertices_list->value_z = z;
00146 
00147       ppsubwin->vertices_list->pNext = NULL;
00148 
00149       pHead = ppsubwin->vertices_list;
00150 
00151     }
00152     vertex_index++;
00153   }
00154 
00155   return 0;
00156 }
00157 /*----------------------------------------------------------------------------------------------*/

Generated on Sun Mar 4 15:03:53 2007 for Scilab [trunk] by  doxygen 1.5.1