*** empty log message ***

This commit is contained in:
Paolo Cignoni cignoni 2008-01-16 19:42:16 +00:00
parent 189808f45b
commit 40d9943817
3 changed files with 77 additions and 7 deletions

View File

@ -1,2 +1,3 @@
12.45 15/01/2008 aggiungere i riferimenti ai nuovi files del progetto al file .pro MAL
22.44 15/01/2008 convertire le QSpinBox per la TranferFunction in double ones
22.44 15/01/2008 convertire le QSpinBox per la TranferFunction in double ones
19.53 16/01/2008 aggiungere alla TF_KEY un campo per capire "a quale punto (su o giù)" è attaccata la linea del grafico!

View File

@ -5,7 +5,10 @@ TfChannel::TfChannel()
{}
TfChannel::TfChannel(TF_CHANNELS type) : _type(type)
{}
{
//no keys, they're sorted
_sorted = true;
}
TfChannel::~TfChannel(void)
{ KEYS.clear(); }
@ -22,6 +25,9 @@ TF_KEY* TfChannel::addKey(TF_KEY &new_key)
{
//inserting at the head of the list
KEYS.insert(KEYS.begin(), new_key);
if ( KEYS.size() >= 2 )
if ( KEYS[0] == KEYS[1] )
this->mergeKeys(0, 1);
return &(*KEYS.begin());
}
@ -67,6 +73,10 @@ float TfChannel::removeKey(float x_val)
return this->removeKey(to_find_key);
}
//da ottimizzare!!
TF_KEY *TfChannel::mergeKeys(int pos1, int pos2)
{ return this->mergeKeys( KEYS[pos1], KEYS[pos2] ); }
//merges two keys together by copying opportunely y values of the keys in just one key
//returns a pointer to the "merged key"
TF_KEY *TfChannel::mergeKeys(TF_KEY key1, TF_KEY key2)
@ -106,7 +116,35 @@ TF_KEY* TfChannel::mergeKeys(float x1, float x2)
float TfChannel::getChannelValuef(float x_position)
{
return x_position;
int prev_key_idx = 0;
int next_key_idx = 0;
//not applicable if list's empty!
assert(KEYS.size() == 0);
//finding upper border key for x_position
while ( (KEYS[next_key_idx].x < x_position) && (next_key_idx < (int)KEYS.size()) )
next_key_idx ++;
//controllare questo! MAL
assert(next_key_idx >= (int)KEYS.size());
//returns the correct value if next_key_idx equals to x_position or when there's only one key in the list
if ((next_key_idx == 0) || (KEYS[next_key_idx].x == x_position))
return KEYS[next_key_idx].junction_point();
assert(next_key_idx == 0);
if ( next_key_idx > 0 )
prev_key_idx = next_key_idx - 1;
//applying linear interpolation between two keys values
//angular coefficient for interpolating line
float m = ((KEYS[next_key_idx].junction_point() - KEYS[prev_key_idx].junction_point()) / (KEYS[next_key_idx].x - KEYS[prev_key_idx].x));
//returning f(x) value for x in the interpolating line
return (m * (x_position - KEYS[prev_key_idx].x)) + KEYS[next_key_idx].junction_point();
}
@ -116,6 +154,13 @@ UINT8 TfChannel::getChannelValueb(float x_position)
// return (UINT8)(this->getChannelValuef(x_position) * 255.0f);
}
//tells if the keys of the channel are sorted
bool TfChannel::isSorted()
{ return _sorted; }
void TfChannel::sortKeys()
{ sort(KEYS.begin(), KEYS.end()); }
@ -145,8 +190,17 @@ TransferFunction::~TransferFunction(void)
void TransferFunction::buildColorBand()
{
//sorting keys of the channel
for (int i=0; i<NUMBER_OF_CHANNELS; i++)
if ( !_channels[i].isSorted() )
_channels[i].sortKeys();
float relative_pos = 0.0f;
for (int i=0; i<COLOR_BAND_SIZE; i++)
_color_band[i].SetRGB( _channels[RED_CHANNEL].getChannelValueb( absolute2RelativeValf((float)i, COLOR_BAND_SIZE) ),
_channels[GREEN_CHANNEL].getChannelValueb( absolute2RelativeValf((float)i, COLOR_BAND_SIZE) ),
_channels[BLUE_CHANNEL].getChannelValueb( absolute2RelativeValf((float)i, COLOR_BAND_SIZE) ) );
{
relative_pos = absolute2RelativeValf((float)i, COLOR_BAND_SIZE);
_color_band[i].SetRGB( _channels[RED_CHANNEL].getChannelValueb( relative_pos ),
_channels[GREEN_CHANNEL].getChannelValueb( relative_pos ),
_channels[BLUE_CHANNEL].getChannelValueb( relative_pos ) );
}
}

View File

@ -35,6 +35,11 @@ using namespace std;
using namespace vcg;
enum JUNCTION_POINT
{
LOWER_Y = 0,
UPPER_Y
};
//struct used to represent each point in the transfer function.
@ -44,13 +49,19 @@ struct TF_KEY
float x;
float y_upper;
float y_lower;
int junction_point_code;
float junction_point() { return junction_point_code == LOWER_Y ? y_lower : y_upper; }
TF_KEY( float x_val=0.0, float y_up=0.0, float y_low=0.0 )
{
x=x_val; y_upper=y_up; y_lower=y_low;
x=x_val; y_upper=y_up; y_lower=y_low; junction_point_code=LOWER_Y;
assert (y_upper < y_lower);
}
void swapY() { float tmp=y_lower; y_lower=y_upper; y_upper=tmp; }
bool operator==(TF_KEY k)
{ return (x == k.x); }
bool operator<(TF_KEY k)
{ return (x < k.x); }
};
//container of TF_KEYs
@ -74,6 +85,7 @@ class TfChannel
{
private:
TF_CHANNELS _type;
bool _sorted;
public:
KEY_LIST KEYS;
@ -89,11 +101,14 @@ public:
TF_KEY *addKey(TF_KEY& new_key);
float removeKey(float x);
float removeKey(TF_KEY& to_remove_key);
TF_KEY *mergeKeys(int pos1, int pos2);
TF_KEY *mergeKeys(float x1, float x2);
TF_KEY *mergeKeys(TF_KEY key1, TF_KEY key2);
float getChannelValuef(float x_position);
UINT8 getChannelValueb(float x_position);
bool isSorted();
void sortKeys();
};