/**\brief Calculates the value from pixel offset */ float Slider::PixelToVal( int pixels ){ float value; value = (TO_FLOAT(pixels) / TO_FLOAT(w)); // Ratio of the pixels value *= (maxval - minval); // Multiply by range value += minval; // Add Baseline return value; }
void en_encoder (bool state,PUCHAR encBaseAddr) #endif { #ifndef WINDOWS_NT word indexPort, dataPort; #else PUCHAR indexPort, dataPort; #endif byte colorTab[256][3]; word i, j; if (state) init_luts(); else { for (i = 0; i < 256; i++) for (j = 0; j < 3; j++) colorTab[i][j] = 0; indexPort = encBaseAddr + 0x10 + 0x00; dataPort = encBaseAddr + 0x10 + 0x01; outp (indexPort, 0); for (i = 0; i < 256; i++) for (j = 0; j < 3; j++) outp (dataPort, colorTab[i][j]); for (i = 0; i < 256; i++) for (j = 0; j < 3; j++) { colorTab[i][j] = (byte)TO_INT((colorTab[i][j] * TO_FLOAT(220) / 256) + TO_FLOAT(16) + (TO_FLOAT(1) / 2) ); // ((double)(colorTab[i][j]*220.0/256.0)+ 16.0 + 0.5) ); } indexPort = encBaseAddr + 0x04 + 0x00; dataPort = encBaseAddr + 0x04 + 0x01; outp (indexPort, 0); for (i = 0; i < 256; i++) for (j = 0; j < 3; j++) outp (dataPort, colorTab[i][j]); #ifndef WINDOWS_NT inp (encBaseAddr + 0x04 + 0x03); /* To activate the CLUT */ #else inp ((PUCHAR)(encBaseAddr + 0x04 + 0x03)); /* To activate the CLUT */ #endif } }
void init_luts() { #ifndef WINDOWS_NT word indexPort, dataPort; #else PUCHAR indexPort, dataPort; #endif byte colorTab[256][3]; word i, j; dword tmp; for (i = 0; i < 256; i++) for (j = 0; j < 3; j++) colorTab[i][j] = (byte)i; indexPort = encBaseAddr + DAC_LUT_CTRL_WR; dataPort = encBaseAddr + DAC_LUT_DATA; outp (indexPort, 0); for (i = 0; i < 256; i++) for (j = 0; j < 3; j++) { tmp = TO_INT((dword)colorTab[i][j] * gain); if (tmp > 0xff) tmp = 0xff; outp (dataPort, (byte)tmp); } for (i = 0; i < 256; i++) for (j = 0; j < 3; j++) { tmp = TO_INT( (((dword)colorTab[i][j] * (dword)220 * gain) / (dword)256) + TO_FLOAT(16) + (TO_FLOAT(1) / 2) ); if ( tmp > 0xeb ) colorTab[i][j] = 0xeb; else colorTab[i][j] = (byte)tmp; } // colorTab[i][j] = (double)(colorTab[i][j]*220.0/256.0) // + 16.0 + 0.5; indexPort = encBaseAddr + DENC_CLUT_CTRL_WR; dataPort = encBaseAddr + DENC_CLUT_DATA; outp (indexPort, 0); for (i = 0; i < 256; i++) for (j = 0; j < 3; j++) outp (dataPort, colorTab[i][j]); inp (encBaseAddr + DENC_DATA_CTRL); /* To activate the CLUT */ }
/**\brief Calculates the marker position from pixel offset. */ int Scrollbar::MarkerPixelToPos( int xr, int yr ){ int effectivelen; int newpos; int marksize = this->GetMarkerSize(); int effectivestart = bitmaps[2]->GetHeight() + marksize / 2; effectivelen = this->h - marksize - bitmaps[1]->GetHeight() - bitmaps[2]->GetHeight(); newpos = TO_INT(TO_FLOAT(yr - effectivestart) / TO_FLOAT(effectivelen) * (maxpos - h)); return newpos; }
/**\brief Calculates the marker position in pixel offset. */ int Scrollbar::MarkerPosToPixel( void ){ int markerpos; int effectivelen; float posratio; // 0 - 1 ratio of marker position effectivelen = this->h - 2 * SCROLLBAR_BTN - this->GetMarkerSize(); posratio = TO_FLOAT(pos) / TO_FLOAT(maxpos - (this-> h + 2 * SCROLLBAR_PAD)); markerpos = SCROLLBAR_BTN + static_cast<int>(effectivelen* posratio); return markerpos; }
/**\brief Calculates the value from pixel offset */ float Slider::PixelToVal( int pixels ){ float value; if ( this->maxval < this->minval ) value = (TO_FLOAT(pixels - SLIDER_MW/2 ) / TO_FLOAT(GetW() - SLIDER_MW)) * ( minval - maxval) + maxval; else value = (TO_FLOAT(pixels - SLIDER_MW/2) / TO_FLOAT(GetW() - SLIDER_MW)) * ( maxval - minval) + minval; return value; }
/**\brief Calculates the marker position in pixel offset. */ int Scrollbar::MarkerPosToPixel( void ){ int markerpos; int effectivelen; float posratio; // 0 - 1 ratio of marker position effectivelen = this->h - GetMarkerSize() - bitmaps[1]->GetHeight() - bitmaps[2]->GetHeight(); posratio = TO_FLOAT(pos) / TO_FLOAT(maxpos - (this-> h )); markerpos = bitmaps[1]->GetHeight() + static_cast<int>(effectivelen* posratio); return markerpos; }
/**\brief Calculates the marker position from pixel offset. */ int Scrollbar::MarkerPixelToPos( int xr, int yr ){ int effectivelen; int screenlen; int newpos; int marksize = this->GetMarkerSize(); int effectivestart = SCROLLBAR_BTN + marksize / 2; effectivelen = this->h - 2 * SCROLLBAR_BTN - marksize; screenlen = this->h + 2 * SCROLLBAR_PAD; newpos = TO_INT(TO_FLOAT(yr - effectivestart) / TO_FLOAT(effectivelen) * (maxpos - screenlen)); return newpos; }
FLOAT /*{ ret - floor(x)}*/ _floorf( FLOAT x /*{ (i) - value for which to compute floorf }*/ ) { FLOAT y; /*{ y = |x| }*/ y = x; if (x < (FLOAT)0.0) { y = -y; } /*{ if x > 2^24 (max 23-bit int), result = x }*/ if (y >= (FLOAT)16777216.0) { return x; } /*{ y = truncate(x) }*/ y = TO_FLOAT(TO_LONG(x)); /*{ if y > x, result = result - 1.0 }*/ if (y > x) { y = SUB(y, 1.0); } return y; }
FLOAT /*{ ret - modf(x)}*/ _modff( FLOAT x, /*{ (i) - value for which to compute modff }*/ FLOAT *i /*{ (o) - address to which integer part is written }*/ ) { FLOAT y; FLOAT fract; /*{ y = |x| }*/ y = x; if (x < (FLOAT)0.0) { y = -y; } /*{ if |x| > 2^24 (max 23-bit int) }*/ if (y >= (FLOAT)16777216.0) { /*{ int = x }*/ /*{ return fract = 0.0 }*/ *i = x; return (FLOAT)0.0; } /*{ if |x| < 1 }*/ if (y < (FLOAT)1.0) { /*{ int = 0 }*/ /*{ return fract = x }*/ *i = (FLOAT)0.0; return x; } /*{ y = truncate(|x|) }*/ y = TO_FLOAT(TO_LONG(y)); /*{ if x < 0, y = -y }*/ if (x < (FLOAT)0.0) { y = -y; } /*{ fract = x - y }*/ fract = SUB(x, y); /*{ *i = y }*/ *i = y; return fract; }
void stage1( SAMPLE *samples, float *floats ) { uint32_t sum = 0; float avg = 0; SUM_DATA( SAMPLES_PER_MSG, samples, sum ); avg = (float) sum / SAMPLES_PER_MSG; TO_FLOAT( SAMPLES_PER_MSG, samples, floats ); ADD_SCALAR( SAMPLES_PER_MSG, floats, -avg ); }
gboolean draw_callback(GtkWidget *widget, cairo_t *cr, gpointer data) { guint width, height; GdkRGBA color; width = gtk_widget_get_allocated_width (widget); height = gtk_widget_get_allocated_height (widget); gtk_style_context_get_color (gtk_widget_get_style_context (widget), 0, &color); gdk_cairo_set_source_rgba (cr, &color); int draw_offset = (int) gtk_adjustment_get_value(scroll_adj); int frames = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(window_spin)); double x = 0.0; double x_step = (double) width / (double) frames; cairo_move_to(cr, x, (height/2.0 - (TO_FLOAT(snd_data[draw_offset]) * height / 2.0 ))); for(int i=1; i < frames; i++) { x += x_step; cairo_line_to(cr, x, (height/2.0 - (TO_FLOAT(snd_data[i+draw_offset]) * height / 2.0 ))); if(i%200 == 0) { cairo_stroke(cr); cairo_move_to(cr, x, (height/2.0 - (TO_FLOAT(snd_data[i+draw_offset]) * height / 2.0 ))); } } cairo_stroke(cr); color.red = 1.0; color.green = color.blue = 0.0; color.alpha = 1.0; gdk_cairo_set_source_rgba(cr, &color); x = 0.0; cairo_move_to(cr, x, (height/2.0 - (TO_FLOAT(p_pos[draw_offset]) * height / 2.0 ))); for(int i=1; i < frames; i++) { x += x_step; cairo_line_to(cr, x, (height/2.0 - (TO_FLOAT(p_pos[i+draw_offset]) * height / 2.0 ))); if(i%200 == 0) { cairo_stroke(cr); cairo_move_to(cr, x, (height/2.0 - (TO_FLOAT(p_pos[i+draw_offset]) * height / 2.0 ))); } } cairo_stroke(cr); cairo_fill (cr); return FALSE; }
void StatusBar::Update( lua_State* L ) { int returnvals, retpos = -1; // Run the StatusBar Updater returnvals = Lua::Run( lua_updater, true ); // Get the new StatusBar Status if (returnvals == 0) { SetName( "" ); SetRatio( 0.0f ); } else if (lua_isnumber(L, retpos) && ( lua_tonumber(L,retpos)>=0.0 && lua_tonumber(L,retpos)<=1.0) ) { SetName( "" ); SetRatio( TO_FLOAT(lua_tonumber(L, retpos)) ); } else if (lua_isstring(L, retpos)) { SetRatio( 0.0f ); SetName( string(lua_tostring(L, retpos)) ); } else { LogMsg(ERR,"Error running '%s': %s", lua_updater.c_str(), lua_tostring(L, retpos)); } lua_pop(L,returnvals); }
/** \brief Create a new Slider * * \returns Lua userdata containing pointer to Slider. */ int UI_Lua::newSlider(lua_State *L){ int n = lua_gettop(L); // Number of arguments if ( (n != 5) && (n != 6) && (n != 7) ) return luaL_error(L, "Got %d arguments expected 5 or 6(x, y, w, h, label, [position], [callback] )", n); int x = int(luaL_checknumber (L, 1)); int y = int(luaL_checknumber (L, 2)); int w = int(luaL_checknumber (L, 3)); int h = int(luaL_checknumber (L, 4)); string label = luaL_checkstring (L, 5); float position = 0.5f; string callback = ""; for(int index=6; index<=7; ++index ) { if ( lua_isnumber(L, index) ) { position = TO_FLOAT( luaL_checknumber(L, index) ); } else if ( lua_isstring(L, index) ) { callback = luaL_checkstring(L, index); } } // Allocate memory for a pointer to object Slider **slider= (Slider**)lua_newuserdata(L, sizeof(Slider**)); luaL_getmetatable(L, EPIAR_UI); lua_setmetatable(L, -2); if (n == 7) { *slider = new Slider(x,y,w,h,label,position,callback); } else if (n == 6) { *slider = new Slider(x,y,w,h,label,position); } else { *slider = new Slider(x,y,w,h,label); } return 1; }
/* * NaN: any float with maximum exponent (0x7f8) and non-zero fraction */ int __cdecl main(int argc, char *argv[]) { /* * Initialize the PAL and return FAIL if this fails */ if (PAL_Initialize(argc, argv) != 0) { return FAIL; } /* * Try some trivial values */ if (_isnanf(0.0f)) { Fail("_isnanf() incorrectly identified %f as NaN!\n", 0.0f); } if (_isnanf(1.234567f)) { Fail("_isnanf() incorrectly identified %f as NaN!\n", 1.234567f); } if (_isnanf(42.0f)) { Fail("_isnanf() incorrectly identified %f as NaN!\n", 42.0f); } UINT32 lneginf = 0xff800000u; UINT32 lposinf = 0x7f800000u; float neginf = TO_FLOAT(lneginf); float posinf = TO_FLOAT(lposinf); /* * Try positive and negative infinity */ if (_isnanf(neginf)) { Fail("_isnanf() incorrectly identified negative infinity as NaN!\n"); } if (_isnanf(posinf)) { Fail("_isnanf() incorrectly identified infinity as NaN!\n"); } /* * Try setting the least significant bit of the fraction, * positive and negative */ UINT32 lsnan = 0xff800001u; float snan = TO_FLOAT(lsnan); if (!_isnanf(snan)) { Fail("_isnanf() failed to identify %I32x as NaN!\n", lsnan); } UINT32 lqnan = 0x7f800001u; float qnan = TO_FLOAT(lqnan); if (!_isnanf(qnan)) { Fail("_isnanf() failed to identify %I32x as NaN!\n", lqnan); } /* * Try setting the most significant bit of the fraction, * positive and negative */ lsnan = 0xffc00000u; snan = TO_FLOAT(lsnan); if (!_isnanf(snan)) { Fail ("_isnanf() failed to identify %I32x as NaN!\n", lsnan); } lqnan = 0x7fc00000u; qnan = TO_FLOAT(lqnan); if (!_isnanf(qnan)) { Fail ("_isnanf() failed to identify %I32x as NaN!\n", lqnan); } PAL_Terminate(); return PASS; }
////////////////////////////////////////////////////////////////////////////////////////////////////// // run a step float Remesh::RunColorStep() { cur_iter++; cerr << "ITERATION ( " << cur_iter << ") " << endl; // COMPUTE THE MESH DISPLACEMENT for (Vertex_iterator vi = data->mesh.p.vertices_begin(); vi!=data->mesh.p.vertices_end(); vi++) { vi->delta = Kernel::Vector_3(0,0,0); vi->delta_tmp = Kernel::Vector_3(0,0,0); } // from current to the closest destination point for (Vertex_iterator vi = data->mesh.p.vertices_begin(); vi!=data->mesh.p.vertices_end(); vi++) { #if MOVE_THE_MESH Kernel::Point_3 closest_point = dst_mesh.closestColorPoint(vi->point(), (float *)(vi->color)); //Kernel::Point_3 closest_point = dst_mesh.closestPoint(vi->point()); #else Kernel::Point_3 tmp_point = vi->point() + vi->motion_vec; Kernel::Point_3 closest_point = dst_mesh.closestColorPoint(tmp_point, (float *)(vi->color)); #endif //cerr << "closest_point (" << closest_point << ") has ID " << dst_mesh.vertex_mapping[closest_point]->id << endl; //Kernel::Vector_3 closest_normal = dst_mesh.vertex_mapping[closest_point]->normal(); //Kernel::Vector_3 closest_normal = dst_mesh.vertexMapping(closest_point)->normal(); /* vi->delta = closest_point - vi->point(); bool is_outside = v_norm((closest_point + closest_normal*v_norm(vi->delta)) - vi->point()) < v_norm(vi->delta); // bool is_outside = v_norm(v_normalized(closest_normal) + v_normalized(vi->delta)) < 1.4142; // bool is_outside = v_angle(closest_normal, vi->delta) > PI/2; double dist_sign = (is_outside?1:-1); vi->delta = vi->normal()*v_norm(vi->delta)*(-1)*dist_sign; */ vi->delta = closest_point- (vi->point() + vi->motion_vec); //vi->delta = vi->normal()* (closest_normal*(closest_point-vi->point())); // vi->delta == v_normalized(data->mesh.computeVectorComponent(vi->normal(),vi->delta,1))*v_norm(vi->delta); // vi->delta = v_normalized(vi->delta)*data->mesh.computeVertexStatistics(*vi,1)*0.05; // vi->delta = vi->normal(); //*alg_dt } // NORMALIZE the movements float total_movement = 0; int total_elements = 0; double max_delta = data->mesh.edge_avg*alg_dt; for (Vertex_iterator vi = data->mesh.p.vertices_begin(); vi!=data->mesh.p.vertices_end(); vi++) { //vi->delta = v_normalized(vi->delta)*data->mesh.computeVertexStatistics(*vi,1)*0.1; // double max_delta = data->mesh.computeVertexStatistics(*vi,1)*alg_dt; // double min_delta = data->mesh.edge_avg/5; // vi->delta = vi->delta; // vi->delta = vi->delta + v_normalized(vi->delta)*(RAND_MAX/2-std::rand())*1.0/RAND_MAX*data->mesh.edge_avg/2*alg_smoothing; // vi->delta = v_normalized(vi->delta)*max_delta; double the_norm = v_norm(vi->delta); if (the_norm > max_delta) { vi->delta = v_normalized(vi->delta)*max_delta; } // if (the_norm < min_delta) vi->delta = v_normalized(vi->delta)*min_delta; the_norm = v_norm(vi->delta); if (! MOVE_THE_MESH || the_norm > max_delta*0.5) { total_elements++; total_movement += v_norm(vi->delta); } //vi->delta = vi->delta + Kernel::Vector_3((RAND_MAX/2-std::rand())*1.0/RAND_MAX, (RAND_MAX/2-std::rand())*1.0/RAND_MAX, (RAND_MAX/2-std::rand())*1.0/RAND_MAX)*data->mesh.computeVertexStatistics(*vi,1)*alg_smoothing; // vi->delta = vi->delta + data->mesh.computeVectorComponent(vi->normal(),vi->laplacian()*alg_dt,0); //vi->delta = vi->delta + vi->laplacian()*alg_smoothing; } data->mesh.diffuse(alg_smoothing, 0); #if ADD_LENGTH_CONSTRAINT for (Vertex_iterator vi = data->mesh.p.vertices_begin(); vi!=data->mesh.p.vertices_end(); vi++) { // Add a cost for preserving the smoothness and the geometry of the mesh HV_circulator h = vi->vertex_begin(); double geom_vx = 0 ; double geom_vy = 0 ; double geom_vz = 0 ; int order=0; do { const float xx = TO_FLOAT ( vi->point().x() ); const float yy = TO_FLOAT ( vi->point().y() ); const float zz = TO_FLOAT ( vi->point().z() ); const float xxx = TO_FLOAT ( h->opposite()->vertex()->point().x()) ; const float yyy = TO_FLOAT ( h->opposite()->vertex()->point().y()) ; const float zzz = TO_FLOAT ( h->opposite()->vertex()->point().z()) ; double d = (xx - xxx) * (xx - xxx) + (yy - yyy) * (yy - yyy) + (zz - zzz) * (zz - zzz) ; #if MOVE_THE_MESH double t_d2x = (xx + vi->delta[0]) - (xxx + h->opposite()->vertex()->delta[0]) ; double t_d2y = (yy + vi->delta[1]) - (yyy + h->opposite()->vertex()->delta[1]) ; double t_d2z = (zz + vi->delta[2]) - (zzz + h->opposite()->vertex()->delta[2]) ; #else double t_d2x = (xx + vi->motion_vec[0] + vi->delta[0]) - (xxx + h->opposite()->vertex()->motion_vec[0] + h->opposite()->vertex()->delta[0]) ; double t_d2y = (yy + vi->motion_vec[1] + vi->delta[1]) - (yyy + h->opposite()->vertex()->motion_vec[1] + h->opposite()->vertex()->delta[1]) ; double t_d2z = (zz + vi->motion_vec[2] + vi->delta[2]) - (zzz + h->opposite()->vertex()->motion_vec[2] + h->opposite()->vertex()->delta[2]) ; #endif double d2 = t_d2x * t_d2x + t_d2y * t_d2y + t_d2z * t_d2z; geom_vx += t_d2x * (sqrt(d2) - sqrt(d)) / sqrt(d2) ; geom_vy += t_d2y * (sqrt(d2) - sqrt(d)) / sqrt(d2) ; geom_vz += t_d2z * (sqrt(d2) - sqrt(d)) / sqrt(d2) ; order++; } while ( ++h != vi->vertex_begin() ); geom_vx /= order ; geom_vy /= order ; geom_vz /= order ; double alpha = 1 ; vi->delta_tmp = alpha * Vector(-geom_vx, -geom_vy, -geom_vz) ; #if 0 if(v_norm(vi->delta_tmp) > 0.001) std::cout << vi->delta << " + " << geom_vx << " " << geom_vy << " " << geom_vz <<std::endl ; #endif } for (Vertex_iterator vi = data->mesh.p.vertices_begin(); vi!=data->mesh.p.vertices_end(); vi++) { double alpha1 = 0.9, alpha2 = 0.1 ; if(v_norm(vi->delta)<0.01) { alpha2 = 0.9; alpha1 = 0.1; } vi->delta = alpha1 * vi->delta + alpha2 * vi->delta_tmp; } #endif // MOVE THE MESH OpenGLContext::mutex.lock(); data->mesh.lock(); for (Vertex_iterator vi = data->mesh.p.vertices_begin(); vi!=data->mesh.p.vertices_end(); vi++) { if (alg_keepVerticesConstant) vi->delta = vi->normal()*(vi->delta*vi->normal()); vi->prev_delta = vi->delta; #if MOVE_THE_MESH vi->move ( vi->delta ); #else vi->motion_vec = vi->motion_vec + vi->delta; #endif } data->mesh.unlock(); #if MOVE_THE_MESH data->mesh.updateMeshData(); #else //for (Vertex_iterator vi = data->mesh.p.vertices_begin(); vi!=data->mesh.p.vertices_end(); vi++) { // vi->motion_vec = vi->motion_vec + vi->laplacian() * alg_smoothing; // smooth the motion vectors //} #endif OpenGLContext::mutex.unlock(); //saveOutput if (alg_saveOutput) { char filename[300]; sprintf(filename,"%s/output_%04d.off",alg_saveOutputPrefix,cur_iter); data->mesh.saveFormat(filename,"off"); sprintf(filename,"%s/output_%04d.diff",alg_saveOutputPrefix,cur_iter); data->mesh.saveVectorField(filename); sprintf(filename,"%s/output_%04d.idx",alg_saveOutputPrefix,cur_iter); data->mesh.saveVertexIndices(filename); } emit stepFinished(); return total_movement; //return total_elements; // return (++cur_iter < iter); }
int __cdecl main(int argc, char **argv) { /*non-finite numbers*/ UINT32 lsnan = 0xffffffffu; UINT32 lqnan = 0x7fffffffu; UINT32 lneginf = 0xff800000u; UINT32 lposinf = 0x7f800000u; float snan = TO_FLOAT(lsnan); float qnan = TO_FLOAT(lqnan); float neginf = TO_FLOAT(lneginf); float posinf = TO_FLOAT(lposinf); /*finite numbers*/ UINT32 lnegunnormalized = 0x807fffffu; UINT32 lposunnormalized = 0x007fffffu; UINT32 lnegzero = 0x80000000u; float negunnormalized = TO_FLOAT(lnegunnormalized); float posunnormalized = TO_FLOAT(lposunnormalized); float negzero = TO_FLOAT(lnegzero); /* * Initialize the PAL and return FAIL if this fails */ if (PAL_Initialize(argc, argv) != 0) { return FAIL; } /*non-finite numbers*/ if (_finitef(snan) || _finitef(qnan)) { Fail("_finitef() found NAN to be finite.\n"); } if (_finitef(neginf)) { Fail("_finitef() found negative infinity to be finite.\n"); } if (_finitef(posinf)) { Fail("_finitef() found infinity to be finite.\n"); } /*finite numbers*/ if (!_finitef(negunnormalized)) { Fail("_finitef() found a negative unnormalized value to be infinite.\n"); } if (!_finitef(posunnormalized)) { Fail("_finitef() found an unnormalized value to be infinite.\n"); } if (!_finitef(negzero)) { Fail("_finitef() found negative zero to be infinite.\n"); } if (!_finitef(+0.0f)) { Fail("_finitef() found zero to be infinite.\n"); } if (!_finitef(-123.456f)) { Fail("_finitef() found %f to be infinite.\n", -123.456f); } if (!_finitef(+123.456f)) { Fail("_finitef() found %f to be infinite.\n", +123.456f); } PAL_Terminate(); return PASS; }