static int draw_button_popup_indicator(Button b, int x, int y, int w, int h, int up) { int rm; /* required right margin */ if ( notNil(b->popup_image) ) { int iw = valInt(b->popup_image->size->w); int ih = valInt(b->popup_image->size->h); rm = iw+8; r_image(b->popup_image, 0, 0, x+w-rm, y + (h-ih)/2, iw, ih, ON); } else { Elevation z = getClassVariableValueObject(b, NAME_elevation); if ( b->look == NAME_motif || b->look == NAME_gtk ) { int bw = 12; int bh = 8; rm = bw+8; r_3d_box(x+w-bw-8, y+(h-bh)/2, bw, bh, 0, z, TRUE); } else { int th = 8; int tw = 9; int tx, ty; rm = tw+8; tx = x+w-rm; ty = y + (h-th)/2; r_3d_triangle(tx+tw/2, ty+th, tx, ty, tx+tw, ty, z, up, 0x3); rm = tw; } } return rm; }
static status RedrawAreaLabel(Label lb, Area a) { int x, y, w, h; Elevation z = lb->elevation; int preview = (lb->status == NAME_preview && notNil(lb->message)); initialiseDeviceGraphical(lb, &x, &y, &w, &h); if ( notNil(z) ) r_3d_box(x, y, w, h, 0, z, !preview); x += valInt(lb->border); y += valInt(lb->border); w -= 2*valInt(lb->border); h -= 2*valInt(lb->border); if ( lb->wrap == NAME_clip ) d_clip(x, y, w, h); if ( instanceOfObject(lb->selection, ClassCharArray) ) { String s = &((CharArray)lb->selection)->data; if ( notNil(z) ) x += valInt(getExFont(lb->font))/2; if ( lb->wrap == NAME_clip ) { LocalString(buf, s->iswide, s->size+1); str_one_line(buf, s); s = buf; } str_label(s, 0, lb->font, x, y, w, h, NAME_left, NAME_top, lb->active == ON ? 0 : LABEL_INACTIVE); } else /*if ( instanceOfObject(lb->selection, ClassImage) )*/ { Image image = (Image) lb->selection; r_image(image, 0, 0, x, y, w, h, ON); } if ( lb->wrap == NAME_clip ) d_clip_done(); if ( preview && isNil(z) ) r_complement(x, y, w, h); return RedrawAreaGraphical(lb, a); }
static status paint_fragment(TextMargin m, int x, int y, Fragment fragment) { Image icon; Style s; int w, h; if ( notNil(s = fragment_style(m, fragment)) && notNil(icon = s->icon) ) { x += margin_x; y += margin_y; w = valInt(icon->size->w); h = valInt(icon->size->h); r_image(icon, 0, 0, x, y, w, h, ON); if ( m->editor->selected_fragment == fragment ) r_complement(x, y, w, h); } succeed; }
/** @brief Process and/or display Ensenso grabber images * @param[in] cloud The Ensenso point cloud * @param[in] images Pair of Ensenso images (raw or with overlay) * @warning Image type changes if a calibration pattern is discovered/lost; * check @c images->first.encoding */ void grabberCallback (const boost::shared_ptr<PointCloudT>& cloud, const boost::shared_ptr<PairOfImages>& images) { viewer_ptr->showCloud (cloud); unsigned char *l_image_array = reinterpret_cast<unsigned char *> (&images->first.data[0]); unsigned char *r_image_array = reinterpret_cast<unsigned char *> (&images->second.data[0]); std::cout << "Encoding: " << images->first.encoding << std::endl; int type = getOpenCVType (images->first.encoding); cv::Mat l_image (images->first.height, images->first.width, type, l_image_array); cv::Mat r_image (images->first.height, images->first.width, type, r_image_array); cv::Mat im (images->first.height, images->first.width * 2, type); im.adjustROI (0, 0, 0, -images->first.width); l_image.copyTo (im); im.adjustROI (0, 0, -images->first.width, images->first.width); r_image.copyTo (im); im.adjustROI (0, 0, images->first.width, 0); cv::imshow ("Ensenso images", im); cv::waitKey (10); }
static status RedrawAreaTextItem(TextItem ti, Area a) { int x, y, w, h; int al, av, am; int lw, lh; int fw = valInt(getExFont(ti->value_text->font)); Elevation z = getClassVariableValueObject(ti, NAME_elevation); int tx, ty, tw, th; TextObj vt = ti->value_text; int flags = 0; initialiseDeviceGraphical(ti, &x, &y, &w, &h); al = valInt(getAscentFont(ti->label_font)); av = valInt(getAscentFont(vt->font)) + valInt(vt->border); am = max(al, av); compute_label_text_item(ti, &lw, &lh); if ( ti->show_label == ON ) { RedrawLabelDialogItem(ti, accelerator_code(ti->accelerator), x, y+am-al, lw-fw, h, ti->label_format, NAME_top, ti->active == ON ? 0 : LABEL_INACTIVE); } tx = x+lw; ty = y+am-av; tw = valInt(vt->area->w); th = valInt(vt->area->h); if ( ti->editable == ON && ti->active == ON ) flags |= TEXTFIELD_EDITABLE; flags |= combo_flags(ti); if ( !ws_entry_field(tx, ty, tw+text_item_combo_width(ti), th, flags) ) { if ( flags & TEXTFIELD_EDITABLE ) { if ( z && notNil(z) ) { int zh = abs(valInt(z->height)); int ly = y+am+zh+valInt(getDescentFont(vt->font)); r_3d_line(x+lw, ly, x+lw+tw, ly, z, TRUE); } else if ( ti->pen != ZERO ) { int pen = valInt(ti->pen); int ly = y+am+1+pen/2; r_dash(ti->texture); r_thickness(valInt(ti->pen)); r_line(x+lw, ly, x+lw+tw, ly); } } if ( flags & (TEXTFIELD_COMBO|TEXTFIELD_COMBO_DOWN) ) { int trh = 8; int trw = 9; int trx, try; int up = (flags & TEXTFIELD_COMBO) ? TRUE : FALSE; trx = tx+tw+5; try = y + (h-trh)/2; r_3d_triangle(trx+trw/2, try+trh, trx, try, trx+trw, try, z, up, 0x3); } if ( flags & TEXTFIELD_STEPPER ) { int sw = STEPPER_BOX_W; int bx = x+w-sw; int bh = (h+1)/2; int iw, ih, ix, dy; Elevation e = getClassVariableValueClass(ClassButton, NAME_elevation); r_3d_box(bx, y, sw, bh, 0, e, !(flags & TEXTFIELD_INCREMENT)); r_3d_box(bx, y+bh, sw, h-bh, 0, e, !(flags & TEXTFIELD_DECREMENT)); iw = valInt(INT_ITEM_IMAGE->size->w)/2; ih = valInt(INT_ITEM_IMAGE->size->h); ix = x + w - (sw+iw+1)/2; dy = (bh-ih+1)/2; r_image(INT_ITEM_IMAGE, 0, 0, ix, y+dy, iw, ih, ON); r_image(INT_ITEM_IMAGE, iw, 0, ix, y+h-dy-ih, iw, ih, ON); } }
RcppExport SEXP antsImageWrite( SEXP r_img , SEXP r_filename ) { try { // check and set the filename if( r_img == NULL || r_filename == NULL ) { Rcpp::stop("Unspecified Arguments"); } bool verbose = false; std::string filename = Rcpp::as< std::string >( r_filename ); Rcpp::S4 r_image( r_img ) ; std::string pixeltype = Rcpp::as< std::string >( r_image.slot( "pixeltype" )); unsigned int dimension = Rcpp::as< unsigned int >( r_image.slot( "dimension" )); unsigned int components = Rcpp::as< unsigned int >( r_image.slot( "components")); if ( (dimension < 2) || (dimension > 4) ) { Rcpp::stop( "Unsupported image dimension"); } if ( (pixeltype != "double") && (pixeltype != "float") && (pixeltype != "unsigned int") && (pixeltype != "unsigned char") ) { Rcpp::stop( "Unsupported pixeltype"); } // write the image if ( pixeltype == "double" ) { typedef double PixelType; if( dimension == 4 ) { const int ImageDimension = 4; typedef itk::Image< PixelType , ImageDimension > ImageType; typedef itk::VectorImage< PixelType, ImageDimension > VectorImageType; (components == 1) ? ants::antsImageWrite< ImageType >( r_img, filename ) : ants::antsImageWrite< VectorImageType >( r_img, filename); if ( verbose ) Rcpp::Rcout << "Done writing image. PixelType: 'double' | Dimension: '4'." << std::endl ; return Rcpp::wrap( 0 ); } else if( dimension == 3 ) { const int ImageDimension = 3 ; typedef itk::Image< PixelType , ImageDimension > ImageType; typedef itk::VectorImage< PixelType, ImageDimension > VectorImageType; (components == 1) ? ants::antsImageWrite< ImageType >( r_img, filename ) : ants::antsImageWrite< VectorImageType >( r_img, filename); if ( verbose ) Rcpp::Rcout << "Done writing image. PixelType: 'double' | Dimension: '4'." << std::endl; return Rcpp::wrap( 0 ) ; } else if( dimension == 2 ) { const int ImageDimension = 2 ; typedef itk::Image< PixelType , ImageDimension > ImageType; typedef itk::VectorImage< PixelType, ImageDimension > VectorImageType; (components == 1) ? ants::antsImageWrite< ImageType >( r_img, filename ) : ants::antsImageWrite< VectorImageType >( r_img, filename); if ( verbose ) Rcpp::Rcout << "Done writing image. PixelType: 'double' | Dimension: '4'." << std::endl; return Rcpp::wrap( 0 ); } } else if ( pixeltype == "float" ) { typedef float PixelType; if( dimension == 4 ) { const int ImageDimension = 4; typedef itk::Image< PixelType , ImageDimension > ImageType; typedef itk::VectorImage< PixelType, ImageDimension > VectorImageType; (components == 1) ? ants::antsImageWrite< ImageType >( r_img, filename ) : ants::antsImageWrite< VectorImageType >( r_img, filename); if ( verbose ) Rcpp::Rcout << "Done writing image. PixelType: 'double' | Dimension: '4'." << std::endl ; return Rcpp::wrap( 0 ); } else if( dimension == 3 ) { const int ImageDimension = 3 ; typedef itk::Image< PixelType , ImageDimension > ImageType; typedef itk::VectorImage< PixelType, ImageDimension > VectorImageType; (components == 1) ? ants::antsImageWrite< ImageType >( r_img, filename ) : ants::antsImageWrite< VectorImageType >( r_img, filename); if ( verbose ) Rcpp::Rcout << "Done writing image. PixelType: 'double' | Dimension: '4'." << std::endl ; return Rcpp::wrap( 0 ) ; } else if( dimension == 2 ) { const int ImageDimension = 2 ; typedef itk::Image< PixelType , ImageDimension > ImageType; typedef itk::VectorImage< PixelType, ImageDimension > VectorImageType; (components == 1) ? ants::antsImageWrite< ImageType >( r_img, filename ) : ants::antsImageWrite< VectorImageType >( r_img, filename); if ( verbose ) Rcpp::Rcout << "Done writing image. PixelType: 'double' | Dimension: '4'." << std::endl ; return Rcpp::wrap( 0 ) ; } } else if ( pixeltype == "unsigned int" ) { typedef unsigned int PixelType; if( dimension == 4 ) { const int ImageDimension = 4; typedef itk::Image< PixelType , ImageDimension > ImageType; typedef itk::VectorImage< PixelType, ImageDimension > VectorImageType; (components == 1) ? ants::antsImageWrite< ImageType >( r_img, filename ) : ants::antsImageWrite< VectorImageType >( r_img, filename); if ( verbose ) Rcpp::Rcout << "Done writing image. PixelType: 'double' | Dimension: '4'." << std::endl ; return Rcpp::wrap( 0 ); } else if( dimension == 3 ) { const int ImageDimension = 3 ; typedef itk::Image< PixelType , ImageDimension > ImageType; typedef itk::VectorImage< PixelType, ImageDimension > VectorImageType; (components == 1) ? ants::antsImageWrite< ImageType >( r_img, filename ) : ants::antsImageWrite< VectorImageType >( r_img, filename); if ( verbose ) Rcpp::Rcout << "Done writing image. PixelType: 'double' | Dimension: '4'." << std::endl ; return Rcpp::wrap( 0 ) ; } else if( dimension == 2 ) { const int ImageDimension = 2 ; typedef itk::Image< PixelType , ImageDimension > ImageType; typedef itk::VectorImage< PixelType, ImageDimension > VectorImageType; (components == 1) ? ants::antsImageWrite< ImageType >( r_img, filename ) : ants::antsImageWrite< VectorImageType >( r_img, filename); if ( verbose ) Rcpp::Rcout << "Done writing image. PixelType: 'double' | Dimension: '4'." << std::endl ; return Rcpp::wrap( 0 ) ; } } else if ( pixeltype == "unsigned char" ) { typedef unsigned char PixelType; if( dimension == 4 ) { const int ImageDimension = 4; typedef itk::Image< PixelType , ImageDimension > ImageType; typedef itk::VectorImage< PixelType, ImageDimension > VectorImageType; (components == 1) ? ants::antsImageWrite< ImageType >( r_img, filename ) : ants::antsImageWrite< VectorImageType >( r_img, filename); if ( verbose ) Rcpp::Rcout << "Done writing image. PixelType: 'double' | Dimension: '4'." << std::endl ; return Rcpp::wrap( 0 ); } else if( dimension == 3 ) { const int ImageDimension = 3 ; typedef itk::Image< PixelType , ImageDimension > ImageType; typedef itk::VectorImage< PixelType, ImageDimension > VectorImageType; (components == 1) ? ants::antsImageWrite< ImageType >( r_img, filename ) : ants::antsImageWrite< VectorImageType >( r_img, filename); if ( verbose ) Rcpp::Rcout << "Done writing image. PixelType: 'double' | Dimension: '4'." << std::endl ; return Rcpp::wrap( 0 ) ; } else if( dimension == 2 ) { const int ImageDimension = 2 ; typedef itk::Image< PixelType , ImageDimension > ImageType; typedef itk::VectorImage< PixelType, ImageDimension > VectorImageType; (components == 1) ? ants::antsImageWrite< ImageType >( r_img, filename ) : ants::antsImageWrite< VectorImageType >( r_img, filename); if ( verbose ) Rcpp::Rcout << "Done writing image. PixelType: 'double' | Dimension: '4'." << std::endl ; return Rcpp::wrap( 0 ) ; } } } catch( const itk::ExceptionObject& err ) { forward_exception_to_r( err ); } catch( const std::exception& exc ) { forward_exception_to_r( exc ); } catch(...) { Rcpp::stop("c++ exception (unknown reason)"); } return Rcpp::wrap(NA_REAL); //not reached }
RcppExport SEXP antsImageWrite( SEXP r_img , SEXP r_filename ) { // check and set the filename if( r_img == NULL || r_filename == NULL ) { Rcpp::Rcout << "Unspecified Arguments" << std::endl ; return Rcpp::wrap( 1 ) ; } std::string filename = Rcpp::as< std::string >( r_filename ) ; Rcpp::S4 r_image( r_img ) ; std::string pixeltype = Rcpp::as< std::string >( r_image.slot( "pixeltype" ) ) ; unsigned int dimension = Rcpp::as< unsigned int >( r_image.slot( "dimension" ) ) ; // write the image if( pixeltype == "double" && dimension == 4 ) { const int ImageDimension = 4 ; typedef double PixelType ; typedef itk::Image< PixelType , ImageDimension > ImageType ; typedef ImageType::Pointer ImagePointerType ; Rcpp::XPtr< ImagePointerType > xptr( static_cast< SEXP >( r_image.slot( "pointer" ) ) ) ; ants::antsImageWrite< ImageType >( *xptr , filename ) ; Rcpp::Rcout << "Done writing image. PixelType: 'double' | Dimension: '4'." << std::endl ; return Rcpp::wrap( 0 ) ; } else if( pixeltype == "double" && dimension == 3 ) { const int ImageDimension = 3 ; typedef double PixelType ; typedef itk::Image< PixelType , ImageDimension > ImageType ; typedef ImageType::Pointer ImagePointerType ; Rcpp::XPtr< ImagePointerType > xptr( static_cast< SEXP >( r_image.slot( "pointer" ) ) ) ; ants::antsImageWrite< ImageType >( *xptr , filename ) ; Rcpp::Rcout << "Done writing image. PixelType: 'double' | Dimension: '3'." << std::endl ; return Rcpp::wrap( 0 ) ; } else if( pixeltype == "double" && dimension == 2 ) { const int ImageDimension = 2 ; typedef double PixelType ; typedef itk::Image< PixelType , ImageDimension > ImageType ; typedef ImageType::Pointer ImagePointerType ; Rcpp::XPtr< ImagePointerType > xptr( static_cast< SEXP >( r_image.slot( "pointer" ) ) ) ; ants::antsImageWrite< ImageType >( *xptr , filename ) ; Rcpp::Rcout << "Done writing image. PixelType: 'double' | Dimension: '2'." << std::endl ; return Rcpp::wrap( 0 ) ; } else if( pixeltype == "float" && dimension == 4 ) { const int ImageDimension = 4 ; typedef float PixelType ; typedef itk::Image< PixelType , ImageDimension > ImageType ; typedef ImageType::Pointer ImagePointerType ; Rcpp::XPtr< ImagePointerType > xptr( static_cast< SEXP >( r_image.slot( "pointer" ) ) ) ; ants::antsImageWrite< ImageType >( *xptr , filename ) ; Rcpp::Rcout << "Done writing image. PixelType: 'float' | Dimension: '4'." << std::endl ; return Rcpp::wrap( 0 ) ; } else if( pixeltype == "float" && dimension == 3 ) { const int ImageDimension = 3 ; typedef float PixelType ; typedef itk::Image< PixelType , ImageDimension > ImageType ; typedef ImageType::Pointer ImagePointerType ; Rcpp::XPtr< ImagePointerType > xptr( static_cast< SEXP >( r_image.slot( "pointer" ) ) ) ; ants::antsImageWrite< ImageType >( *xptr , filename ) ; Rcpp::Rcout << "Done writing image. PixelType: 'float' | Dimension: '3'." << std::endl ; return Rcpp::wrap( 0 ) ; } else if( pixeltype == "float" && dimension == 2 ) { const int ImageDimension = 2 ; typedef float PixelType ; typedef itk::Image< PixelType , ImageDimension > ImageType ; typedef ImageType::Pointer ImagePointerType ; Rcpp::XPtr< ImagePointerType > xptr( static_cast< SEXP >( r_image.slot( "pointer" ) ) ) ; ants::antsImageWrite< ImageType >( *xptr , filename ) ; Rcpp::Rcout << "Done writing image. PixelType: 'float' | Dimension: '2'." << std::endl ; return Rcpp::wrap( 0 ) ; } else if( pixeltype == "unsigned int" && dimension == 4 ) { const int ImageDimension = 4 ; typedef unsigned int PixelType ; typedef itk::Image< PixelType , ImageDimension > ImageType ; typedef ImageType::Pointer ImagePointerType ; Rcpp::XPtr< ImagePointerType > xptr( static_cast< SEXP >( r_image.slot( "pointer" ) ) ) ; ants::antsImageWrite< ImageType >( *xptr , filename ) ; Rcpp::Rcout << "Done writing image. PixelType: 'unsigned int' | Dimension: '4'." << std::endl ; return Rcpp::wrap( 0 ) ; } else if( pixeltype == "unsigned int" && dimension == 3 ) { const int ImageDimension = 3 ; typedef unsigned int PixelType ; typedef itk::Image< PixelType , ImageDimension > ImageType ; typedef ImageType::Pointer ImagePointerType ; Rcpp::XPtr< ImagePointerType > xptr( static_cast< SEXP >( r_image.slot( "pointer" ) ) ) ; ants::antsImageWrite< ImageType >( *xptr , filename ) ; Rcpp::Rcout << "Done writing image. PixelType: 'unsigned int' | Dimension: '3'." << std::endl ; return Rcpp::wrap( 0 ) ; } else if( pixeltype == "unsigned int" && dimension == 2 ) { const int ImageDimension = 2 ; typedef unsigned int PixelType ; typedef itk::Image< PixelType , ImageDimension > ImageType ; typedef ImageType::Pointer ImagePointerType ; Rcpp::XPtr< ImagePointerType > xptr( static_cast< SEXP >( r_image.slot( "pointer" ) ) ) ; ants::antsImageWrite< ImageType >( *xptr , filename ) ; Rcpp::Rcout << "Done writing image. PixelType: 'unsigned int' | Dimension: '2'." << std::endl ; return Rcpp::wrap( 0 ) ; } else if( pixeltype == "unsigned char" && dimension == 4 ) { const int ImageDimension = 4 ; typedef unsigned char PixelType ; typedef itk::Image< PixelType , ImageDimension > ImageType ; typedef ImageType::Pointer ImagePointerType ; Rcpp::XPtr< ImagePointerType > xptr( static_cast< SEXP >( r_image.slot( "pointer" ) ) ) ; ants::antsImageWrite< ImageType >( *xptr , filename ) ; Rcpp::Rcout << "Done writing image. PixelType: 'unsigned char' | Dimension: '4'." << std::endl ; return Rcpp::wrap( 0 ) ; } else if( pixeltype == "unsigned char" && dimension == 3 ) { const int ImageDimension = 3 ; typedef unsigned char PixelType ; typedef itk::Image< PixelType , ImageDimension > ImageType ; typedef ImageType::Pointer ImagePointerType ; Rcpp::XPtr< ImagePointerType > xptr( static_cast< SEXP >( r_image.slot( "pointer" ) ) ) ; ants::antsImageWrite< ImageType >( *xptr , filename ) ; Rcpp::Rcout << "Done writing image. PixelType: 'unsigned char' | Dimension: '3'." << std::endl ; return Rcpp::wrap( 0 ) ; } else if( pixeltype == "unsigned char" && dimension == 2 ) { const int ImageDimension = 2 ; typedef unsigned char PixelType ; typedef itk::Image< PixelType , ImageDimension > ImageType ; typedef ImageType::Pointer ImagePointerType ; Rcpp::XPtr< ImagePointerType > xptr( static_cast< SEXP >( r_image.slot( "pointer" ) ) ) ; ants::antsImageWrite< ImageType >( *xptr , filename ) ; Rcpp::Rcout << "Done writing image. PixelType: 'unsigned char' | Dimension: '2'." << std::endl ; return Rcpp::wrap( 0 ) ; } else { Rcpp::Rcout << "Usupported PixelType or Dimension" << std::endl ; return Rcpp::wrap( 1 ) ; } }