Changeset 11887


Ignore:
Timestamp:
04/03/12 16:49:10 (13 years ago)
Author:
Eric.Larour
Message:

Contour is now a class

Location:
issm/trunk-jpl/src/c/objects
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/objects/Contour.cpp

    r9761 r11887  
    1313#include "../io/io.h"
    1414
    15 void ContourEcho(Contour* contour){
     15/*Contour constructors and destructors:*/
     16/*FUNCTION Contour::Contour() default constructor {{{1*/
     17Contour::Contour(){
     18        this->id=0;
     19        this->nods=0;
     20        this->x=NULL;
     21        this->y=NULL;
     22        this->closed=false;
     23}
     24/*}}}*/
     25/*FUNCTION Contour::Contour(int pid, int nods, double* x, double* y,bool closed) {{{1*/
     26Contour::Contour(int pid,int pnods, double* px, double* py,bool pclosed){
     27       
     28        this->id=pid;
     29        this->nods=pnods;
     30        this->closed=pclosed;
     31        if(nods){
     32                this->x=(double*)xmalloc(nods*sizeof(double));
     33                memcpy(this->x,px,nods*sizeof(double));
     34                this->y=(double*)xmalloc(nods*sizeof(double));
     35                memcpy(this->y,py,nods*sizeof(double));
     36        }
     37}
     38/*}}}*/
     39/*FUNCTION Contour::Contour() default constructor {{{1*/
     40Contour::~Contour(){
     41        xfree((void**)&this->x);
     42        xfree((void**)&this->y);
     43}
     44/*}}}*/
     45
     46
     47/*Object virtual function resolutoin: */
     48/*FUNCTION Contour::Echo(){{{1*/
     49void Contour::Echo(void){
    1650
    1751        int i;
    1852
    19         _printf_(true,"Number of nodes in contour: %i\n",contour->nods);
    20         _printf_(true,"Node coordinates: \n");
    21         for (i=0;i<contour->nods;i++){
    22                 _printf_(true,"%lf %lf\n",*(contour->x+i),*(contour->y+i));
     53        printf("Contour: %i:\n",id);
     54        printf("   nods: %i\n",nods);
     55        printf("   closed: %s\n",closed?"true":"false");
     56        if(nods){
     57                printf("   x,y:\n");
     58                for(i=0;i<nods;i++){
     59                        printf("%i: %g|%g\n",i,x[i],y[i]);
     60                }
    2361        }
    2462}
     63/*}}}*/
     64/*FUNCTION Contour::DeepEcho(){{{1*/
     65void Contour::DeepEcho(void){
     66        this->Echo();
     67}
     68/*}}}*/
     69/*FUNCTION Contour::Id(){{{1*/
     70int Contour::Id(void){
     71        return id;
     72}
     73/*}}}*/
     74/*FUNCTION Contour::MyRank{{{1*/
     75int    Contour::MyRank(void){
     76        extern int my_rank;
     77
     78        return my_rank;
     79}
     80/*}}}*/
     81#ifdef _SERIAL_
     82/*FUNCTION Contour::Marshall{{{1*/
     83void  Contour::Marshall(char** pmarshalled_dataset){
     84
     85        char* marshalled_dataset=NULL;
     86        int   enum_type=0;
     87        char* marshalled_inputs=NULL;
     88        int   marshalled_inputssize;
     89
     90        /*recover marshalled_dataset: */
     91        marshalled_dataset=*pmarshalled_dataset;
     92
     93        /*get enum type of Contour: */
     94        enum_type=ContourEnum;
     95       
     96        /*marshall enum: */
     97        memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
     98       
     99        /*marshall Contour data: */
     100        memcpy(marshalled_dataset,&id,sizeof(id));marshalled_dataset+=sizeof(id);
     101        memcpy(marshalled_dataset,&nods,sizeof(nods));marshalled_dataset+=sizeof(nods);
     102        memcpy(marshalled_dataset,&closed,sizeof(closed));marshalled_dataset+=sizeof(closed);
     103        memcpy(marshalled_dataset,x,nods*sizeof(double));marshalled_dataset+=nods*sizeof(double);
     104        memcpy(marshalled_dataset,y,nods*sizeof(double));marshalled_dataset+=nods*sizeof(double);
     105
     106        *pmarshalled_dataset=marshalled_dataset;
     107        return;
     108}
     109/*}}}*/
     110/*FUNCTION Contour::MarshallSize{{{1*/
     111int   Contour::MarshallSize(){
     112
     113        return sizeof(id)+
     114                sizeof(nods)+
     115                sizeof(closed)+
     116                2*nods*sizeof(double)+
     117                sizeof(int); //sizeof(int) for enum type
     118}
     119/*}}}*/
     120/*FUNCTION Contour::Demarshall{{{1*/
     121void  Contour::Demarshall(char** pmarshalled_dataset){
     122
     123        char* marshalled_dataset=NULL;
     124
     125        /*recover marshalled_dataset: */
     126        marshalled_dataset=*pmarshalled_dataset;
     127
     128        /*this time, no need to get enum type, the pointer directly points to the beginning of the
     129         *object data (thanks to DataSet::Demarshall):*/
     130
     131        memcpy(&id,marshalled_dataset,sizeof(id));marshalled_dataset+=sizeof(id);
     132        memcpy(&nods,marshalled_dataset,sizeof(nods));marshalled_dataset+=sizeof(nods);
     133        memcpy(&closed,marshalled_dataset,sizeof(closed));marshalled_dataset+=sizeof(closed);
     134
     135        if(nods){
     136                this->x=(double*)xmalloc(nods*sizeof(double));
     137                this->y=(double*)xmalloc(nods*sizeof(double));
     138                memcpy(x,marshalled_dataset,nods*sizeof(double));marshalled_dataset+=nods*sizeof(double);
     139                memcpy(y,marshalled_dataset,nods*sizeof(double));marshalled_dataset+=nods*sizeof(double);
     140        }
     141
     142        /*return: */
     143        *pmarshalled_dataset=marshalled_dataset;
     144        return;
     145}
     146/*}}}*/
     147#endif
     148/*FUNCTION Contour::ObjectEnum{{{1*/
     149int Contour::ObjectEnum(void){
     150
     151        return ContourEnum;
     152
     153}
     154/*}}}*/
     155/*FUNCTION Contour::copy {{{1*/
     156Object* Contour::copy() {
     157
     158        return new Contour(*this);
     159
     160}
     161/*}}}*/
  • issm/trunk-jpl/src/c/objects/Contour.h

    r3420 r11887  
    1 /*! \file Contour.h
    2  *  \brief structure object to hold contour profiles from an
    3  *  Argus domain outline file, or from any cad system.
     1/*!\file Contour.h
     2 * \brief: header file for Contour object
    43 */
    54
     
    76#define _CONTOUR_H_
    87
    9 /*!Contour declaration: */
    10 struct Contour {
    11         int     nods;
    12         double* x;
    13         double* y;
     8/*Headers:*/
     9/*{{{1*/
     10#include "./Object.h"
     11#include "../shared/Exceptions/exceptions.h"
     12#include "../toolkits/toolkits.h"
     13#include "../include/include.h"
     14/*}}}*/
     15
     16class Contour: public Object{
     17
     18        public:
     19
     20                int     id;
     21                int         nods;  //number of vertices in the contour
     22                double* x;
     23                double* y;
     24                bool    closed; //is this contour closed?
     25
     26                /*Contour constructors, destructors {{{1*/
     27                Contour();
     28                Contour(int id, int nods, double* x, double* y,bool closed);
     29                ~Contour();
     30                /*}}}*/
     31                /*Object virtual functions{{{1*/
     32                void  Echo(void);
     33                void  DeepEcho(void);
     34                int   Id(void);
     35                int   MyRank(void);
     36                #ifdef _SERIAL_
     37                void  Marshall(char** pmarshalled_dataset);
     38                int   MarshallSize(void);
     39                void  Demarshall(char** pmarshalled_dataset);
     40                #endif
     41                int   ObjectEnum(void);
     42                Object* copy(void);
     43                /*}}}*/
     44
     45
    1446};
    1547
    16 /*!Methods: */
    17 void ContourEcho(Contour* contour);
    18 
    19 #endif  /* CONTOUR_H_ */
     48#endif  /* _CONTOUR_H_ */
Note: See TracChangeset for help on using the changeset viewer.