00001
00002
00003
00004
00005
00006
00007
00008 #ifndef STRING_EL_H
00009 #define STRING_EL_H
00010
00011 #include <boost/shared_ptr.hpp>
00012 #include "edgel.h"
00013 #include <list>
00014
00015 #define EDGE_GET_CONN_MASK 0x000000F0
00016 #define EDGE_SET_CONN_MASK 0xFFFFFF0F
00017 #define EDGE_CONN 0x00000020
00018
00019 namespace mimas {
00020
00022 typedef enum { unconnected, connection, junction, termination }connect_type ;
00023
00024 class string_el;
00025 class property_image;
00026
00028 typedef boost::shared_ptr< string_el > string_el_ptr;
00029
00031 typedef std::list< boost::shared_ptr< string_el > > string_el_ptr_list;
00032
00034 class string_el : public edgel
00035 {
00036
00037
00038 private:
00039 int flags;
00040 std::list< boost::weak_ptr< string_el > > conn_list;
00041 boost::weak_ptr< string_el > conn_c1, conn_c2;
00042
00043 int spur_len;
00044 bool remove_me;
00045 bool loop;
00046 connect_type connect;
00047
00048
00049 public:
00050 string_el( const edgel &e )
00051 {
00052 setPropertyType(edge_string_t);
00053
00054
00055 flags =0;
00056 flags&=EDGE_SET_CONN_MASK;
00057 flags|=EDGE_CONN;
00058
00059 spur_len = 0;
00060 remove_me = false;
00061 loop = false;
00062 connect = unconnected;
00063
00064
00065
00066
00067 edgel::operator=( e );
00068 }
00069
00070 void draw( image< rgba< unsigned char > >& output,
00071 int i, int j, bool c)
00072 {
00073
00074
00075 int s = (int)getStrength();
00076
00077
00078 if (c)
00079 {
00080 if (s<50)
00081 s*=5;
00082 else
00083 s=255;
00084 }
00085 else
00086 s=255;
00087
00088 switch( connect )
00089 {
00090 case unconnected: output.setPixel( i,j, rgba< unsigned char >(s,0,0) );
00091 break;
00092 case connection: output.setPixel( i,j, rgba< unsigned char >(s,0,s) );
00093 break;
00094 case junction: output.setPixel( i,j, rgba< unsigned char >(0,s,s) );
00095 break;
00096 case termination: output.setPixel( i,j, rgba< unsigned char >(0,0,s) );
00097 break;
00098
00099 }
00100 }
00101
00102 string_el_ptr getConnC1()
00103 { return !conn_c1.expired() ? string_el_ptr( conn_c1 ) : string_el_ptr(); }
00104 string_el_ptr getConnC2()
00105 { return !conn_c2.expired() ? string_el_ptr( conn_c2 ) : string_el_ptr(); }
00106 const string_el_ptr getConnC1() const
00107 { return !conn_c1.expired() ? string_el_ptr( conn_c1 ) : string_el_ptr(); }
00108 const string_el_ptr getConnC2() const
00109 { return !conn_c2.expired() ? string_el_ptr( conn_c2 ) : string_el_ptr(); }
00110 void setConnC1( boost::weak_ptr< string_el > d) { conn_c1 = d; }
00111 void setConnC2( boost::weak_ptr< string_el > d) { conn_c2 = d; }
00112 std::list< boost::weak_ptr< string_el > >& getConnList()
00113 { return conn_list; }
00114 const std::list< boost::weak_ptr< string_el > >& getConnList() const
00115 { return conn_list; }
00116 int getSpurLen(){ return spur_len; }
00117 void setSpurLen(int s) { spur_len=s; }
00118 void delConnList()
00119 {
00120 conn_list.clear();
00121
00122 }
00123 void setRemoveMe() { remove_me = true; }
00124 void resetRemoveMe() {remove_me=false;}
00125 bool removeMe() { return remove_me; }
00126 connect_type getConnectType(){ return connect; }
00127 void setConnectType( connect_type c) { connect=c;}
00128 bool isLoop() { return loop; }
00129 void setLoop(bool b) { loop= b; }
00130 edgel* getEdgel() { return (edgel*)this; }
00131
00132
00133 void edgeSetConns( property_image& esim, int x, int y,
00134 string_el_ptr_list& junc_list,
00135 string_el_ptr_list& term_list );
00136 };
00137
00138 }
00139 #endif