userselection.h 4.03 KB
Newer Older
jcl's avatar
jcl committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
// ============================================================================
// Copyright Jean-Charles LAMBERT - 2008-2010                                       
// e-mail:   Jean-Charles.Lambert@oamp.fr                                      
// address:  Dynamique des galaxies                                            
//           Laboratoire d'Astrophysique de Marseille                          
//           Pole de l'Etoile, site de Chateau-Gombert                         
//           38, rue Frederic Joliot-Curie                                     
//           13388 Marseille cedex 13 France                                   
//           CNRS U.M.R 6110                                                   
// ============================================================================
#ifndef UNSUSERSELECTION_H
#define UNSUSERSELECTION_H
/**
	@author Jean-Charles Lambert <jean-charles.lambert@oamp.fr>
*/
#include <string>
#include <vector>
#include "componentrange.h"

namespace uns {
#define HaloBit     (1  <<  0)
#define DiskBit     (1  <<  1)
#define BulgeBit    (1  <<  3)
#define StarsBit    (1  <<  4)
#define GasBit      (1  <<  5)
  struct indexes_tab { int i,p; };
  typedef struct indexes_tab t_indexes_tab;
class  ParticlesObject;
typedef std::vector <ParticlesObject> ParticlesObjectVector; 

class UserSelection{
// this class allows to the user to check if the components/range she/he has
// selected match with the components returned by the snapshot's plugin.    
//                                                                          
public:
  UserSelection();
  //const UserSelection& operator=(const UserSelection& m);
  ~UserSelection();
39
  bool setSelection(const std::string,const ComponentRangeVector *, bool nodata=false);
jcl's avatar
jcl committed
40 41 42 43 44
  const t_indexes_tab * getIndexesTab() const { return indx; }
  int   getNSel()       const { return nsel   ; }
  static std::string parseString(std::string&);
  ComponentRangeVector * getCrvFromSelection() { return &crvsel;}
  int compBits() { return comp_bits; }
jclamber's avatar
jclamber committed
45 46 47 48 49 50 51
  std::vector <int> selectOrder() {
    return select_order;
  }
  void setCrv(ComponentRangeVector _crv) {
    crvsel = _crv;
  }

jcl's avatar
jcl committed
52 53 54 55 56 57 58
private:
  ParticlesObjectVector pov;
  static int comparePos(const void * a, const void * b) {
    t_indexes_tab * aa = (t_indexes_tab *) a;
    t_indexes_tab * bb = (t_indexes_tab *) b;
    return (aa->p - bb->p);
  }
jclamber's avatar
jclamber committed
59
  std::vector <int> select_order;
jcl's avatar
jcl committed
60 61 62 63 64 65
  std::string select;           // input range (console | GUI)
  bool parse();                 // parse selection
  int parseComponent(const std::string);
  bool checkComponent(const std::string);
  int isComponent(const std::string);
  int isRange(const std::string);
66
  bool nodata; // no data before setSelection
jcl's avatar
jcl committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
  std::string out_range;            // range selected             
  int nbody;                        // #bodies max                
  int nsel;                         // #bodies selected           
  int pos;                          // current component position 
  int comp_bits;                    // components bits requested
  const ComponentRangeVector * crv; // vector of component range  
  ComponentRangeVector crvsel;      // crv for selected components
  void fillIndexes(const std::string, const int, const int, const int, int);
  void crvResize(ComponentRangeVector&);
  int crvPermut(ComponentRange&, const int, const int, int&);
  t_indexes_tab * indx;
  int min,max;
  void findMinMax(const int, const int);
};
//
// class ParticlesObject
//
// this class is used to re-ordering the object according to
// user selection
class ParticlesObject{
  public:
  ParticlesObject() {
    npart=0;    
    step=first=last=-1;
    pos=-1;
  }

  const ParticlesObject& operator=(const ParticlesObject&m) {
    npart = m.npart;
    first = m.first;
    last  = m.last;
    pos   = m.pos;
    return *this;
  }

  int npart;       // #particles in the object
  int first;       // index of the first particle
  int last;        // index of the last particle
  int step;        // incremental step between particles.
  int pos;         // position of the object
};

}
#endif