Example #1
0
NeuralNet::NeuralNet(size_t no_inputs, size_t no_hidden, size_t no_outputs, ActivationFunc& hidden_act, ActivationFunc& output_act)
{
    NNLayer hidden_layer(no_inputs, no_hidden, hidden_act);
    NNLayer output_layer(no_hidden, no_outputs, output_act);
    add_layer(hidden_layer);
    add_layer(output_layer);
}
Example #2
0
int main(int argc, char **argv)
{
    int     i;
    int     errors;
    DataSet *train_set;
    DataSet *test_set;
    Network *adultnn = create_network(14);
    double  e;
    double  acc;
    Class   predicted, desired;

    // training
    train_set = read_dataset("adult.train");

    if (train_set == NULL) {
        fprintf(stderr, "Error reading training set\n");
        exit(1);
    }

    add_layer(adultnn, 28);  // hidden layer
    add_layer(adultnn, 2);  // output layer
    initialize_weights(adultnn, SEED);
    print_network_structure(adultnn);

    printf("Training network with %d epochs...\n", EPOCHS);
    e = batch_train(adultnn, train_set, LEARNING_RATE, EPOCHS,
                   sigmoid, dsigmoid);
    printf("Training finished, approximate final SSE: %f\n", e);

    print_network_structure(adultnn);

    // testing
    test_set = read_dataset("adult.test");

    if (test_set == NULL) {
        fprintf(stderr, "Error reading test set\n");
        exit(1);
    }

    errors = 0;
    printf("Testing with %d cases...\n", test_set->n_cases);
    for (i = 0; i < test_set->n_cases; ++i) {
        predicted = predict_class(adultnn, test_set->input[i]);
        desired = output_to_class(test_set->output[i]);
        if (predicted != desired)
            ++errors;
        printf("Case %d | predicted: %s, desired: %s, outputs: %4.3f %4.3f \n", i,
               class_to_string(predicted), class_to_string(desired),
               adultnn->output_layer->y[0], adultnn->output_layer->y[1]);
    }

    acc = 100.0 - (100.0 * errors / test_set->n_cases);
    printf("Testing accuracy: %f\n", acc);
    printf("Total classificarion errors: %d\n", errors);

    destroy_dataset(train_set);
    destroy_dataset(test_set);

    return 0;
}
Example #3
0
CPVLayerGroup::CPVLayerGroup(counter_t anSpan, counter_t anPool, counter_t anInput, std::string aLayerID):
                             VLayerGroup(aLayerID)
{
  fLayerType=kConvoPoolVLayerGroup;
  fConvoLayer= new CNLayer(anSpan,0,anInput);
  add_layer(fConvoLayer);
  fPoolLayer= new PNLayer(anPool,fConvoLayer->get_noutput());
  add_layer(fPoolLayer);
}
Example #4
0
void PointSet::build_from_image(CVD::Image<unsigned char>& im1, Image<TooN::Vector<2, float> >& xy_lookup, bool const use_rhips){
	database.clear();

	//add_layer(im1, xy_lookup, 1, use_rhips);

	Image<unsigned char> halfimage= halfsize(im1);
	add_layer(halfimage, xy_lookup, 2, use_rhips);
	
	Image<unsigned char> quartimage= halfsize(halfimage);
	add_layer(quartimage, xy_lookup, 4, use_rhips);
}
Example #5
0
void rotation_verticale(t_display display)
{
		int x, y;

    Uint32 pixel_s, pixel;

		for (y = 0 ; y < WINY; y ++)
        {
                for ( x = 0 ; x < WINX/2; x ++)
                {
                        pixel_s = *((Uint32*)(display.screen->pixels) + x + y * WINX);
												pixel 	=	*((Uint32*)(display.screen->pixels) + WINX - 1 - x + y * WINX);
											
												setPixel(&display, WINX - 1 - x, y, pixel_s);	
												setPixel(&display, x, y, pixel);

                }
        }

	SDL_Flip(display.screen);
	SDL_Rect		pos_0;

    pos_0.x = 0;
    pos_0.y = 0;

	add_layer(&display.layers, display.screen, &pos_0);


}
Example #6
0
/*
* Compress a message
*/
void CMS_Encoder::compress(const std::string& algo)
   {
   if(!CMS_Encoder::can_compress_with(algo))
      throw Invalid_Argument("CMS_Encoder: Cannot compress with " + algo);

   Filter* compressor = 0;

#if defined(BOTAN_HAS_COMPRESSOR_ZLIB)
   if(algo == "Zlib") compressor = new Zlib_Compression;
#endif

   if(compressor == 0)
      throw Internal_Error("CMS: Couldn't get ahold of a compressor");

   Pipe pipe(compressor);
   pipe.process_msg(data);
   SecureVector<byte> compressed = pipe.read_all();

   DER_Encoder encoder;
   encoder.start_cons(SEQUENCE).
      encode(static_cast<size_t>(0)).
      encode(AlgorithmIdentifier("Compression." + algo,
                                 MemoryVector<byte>())).
      raw_bytes(make_econtent(compressed, type)).
   end_cons();

   add_layer("CMS.CompressedData", encoder);
   }
Scale_analysis_2::Scale_analysis_2() : Geometry() {
	has_ordered_balls = has_balls = has_points = false;

	GL_draw_layer_2* balls_center_layer = new Scale_analysis_balls_layer_2("SA balls center", this, "Balls used for scale analysis");
	add_layer(balls_center_layer);
	GL_draw_layer_2* circles_layer = new Scale_analysis_balls_layer_2("SA circles", this, "Balls used for scale analysis", true);
	add_layer(circles_layer);
	GL_draw_layer_2* disks_center_layer = new Scale_analysis_balls_layer_2("SA disks", this, "Balls used for scale analysis", true, true);
	add_layer(disks_center_layer);

	GL_draw_layer_2* scaled_circles_layer = new Scale_analysis_balls_layer_2("SA scaled circles", this, "Balls used for scale analysis, scaled as the application parameter says", true, false, true);
	add_layer(scaled_circles_layer);
	GL_draw_layer_2* scaled_disks_center_layer = new Scale_analysis_balls_layer_2("SA scaled disks", this, "Balls used for scale analysis, scaled as the application parameter says", true, true, true);
	add_layer(scaled_disks_center_layer);

}
/**
 * Write out the text and markup files to JNI objects
 * @param env the JNI environment
 * @param u userdata
 * @param text text object
 * @param markup markup object
 */
void userdata_write_files( JNIEnv *env, userdata *u, jobject text, 
    jobject markup )
{
    // write out text
    dest_file_close( u->text_dest, 0 );
    int tlen = dest_file_len( u->text_dest );
    // save result to text and markup objects
    int res = set_string_field( env, text, "body", 
        ramfile_get_buf(dest_file_dst(u->text_dest)) );
    dest_file_dispose( u->text_dest );
    int i=0;
    while ( u->markup_dest[i] != NULL && res )
    {
        dest_file_close( u->markup_dest[i], tlen );
        if ( res ) 
        {
            DST_FILE *df = dest_file_dst(u->markup_dest[i]);
            if ( i == 0 )
            {
                res = set_string_field( env, markup, "body", 
                    ramfile_get_buf(df) );
            }
            else
            {
                res = add_layer( env, markup, ramfile_get_buf(df) );
            }
        }
        dest_file_dispose( u->markup_dest[i++] );
    }
}
Example #9
0
void rotation_horizontale(t_display display)
{
		int x, y;

		Uint32 pixel_s, pixel;

		for (y = 0 ; y < 500; y ++)
        {
                for ( x = 0 ; x < WINX; x ++)
                {
                        pixel_s = *((Uint32*)(display.screen->pixels) + x + y * WINX);
												pixel 	=	*((Uint32*)(display.screen->pixels) + x + WINX * (WINY - 1 - y));
											
												setPixel(&display, x, WINY - 1 - y, pixel_s);	
												setPixel(&display, x, y, pixel);

                }
        }

	SDL_Flip(display.screen);
	SDL_Rect		pos_0;

    pos_0.x = 0;
    pos_0.y = 0;

	add_layer(&display.layers, display.screen, &pos_0);

}
Example #10
0
void image_new_blank(image_t *image, gdouble rel_w, gdouble rel_h) {
    double w, h;
    get_abs_pos(rel_w, rel_h, &w, &h);
    image->layer = create_layer(w, h);
    image->rotation = 0;
    image->surface = create_surface(w, h);
    image->pbuf = NULL;
    
    add_layer(image->layer);
}
QcGermanyPlugin::QcGermanyPlugin()
  : QcWmtsPlugin(PLUGIN_NAME, PLUGIN_TITLE,
                 new QcMercatorTileMatrixSet(NUMBER_OF_LEVELS, TILE_SIZE))
{

  int map_id = -1;
  add_layer(new QcGermanyLayer(this,
                               ++map_id, // 1
                               1,
                               QLatin1Literal("Map"),
                               QLatin1Literal("webatlasde"),
                               QLatin1Literal("png")
                               ));
}
void ImageGroundTruthPanelViewer::Initialize()
{
    mp_editor_bar->ToggleTool(ID_MODE_NAVIGATION, false);
    mp_editor_bar->ToggleTool(ID_MODE_CAPTURE, true);
    mp_editor_bar->EnableTool(wxID_SAVE, false);
    mp_editor_bar->EnableTool(wxID_FORWARD, false);
    mp_editor_bar->EnableTool(wxID_BACKWARD, false);
    mp_editor_bar->EnableTool(wxID_UNDO, false);
    mp_editor_bar->EnableTool(wxID_REDO, false);

    m_is_last_event_related_to_openings = true;
    mp_opening_layer = vector_layer_ptr_t(new simple_vector_layer("ouvertures"));
    mp_occlusion_layer = vector_layer_ptr_t(new simple_vector_layer("occlusions"));
    add_layer(mp_opening_layer);
    add_layer(mp_occlusion_layer);
    mp_opening_layer->polygon_border_color(* wxRED);
    mp_occlusion_layer->polygon_border_color(wxColor(255, 255, 0));
    mp_opening_layer->polygon_inner_style(wxTRANSPARENT);
    mp_occlusion_layer->polygon_inner_style(wxTRANSPARENT);
    Refresh();
    geometry_rectangle();
    mode_capture();
    SetFocus();
}
Example #13
0
gboolean image_new(image_t *image, const char *filename) {
    GError **error = NULL;
    image->pbuf = gdk_pixbuf_new_from_file(filename, error);
    if (!image->pbuf)
        return FALSE;
    image->layer = create_layer(gdk_pixbuf_get_width(image->pbuf),
                                gdk_pixbuf_get_height(image->pbuf));
    
    image->rotation = 0;
    
    image->surface = create_surface(image->layer->width, image->layer->height);
    cairo_t *cr = cairo_create(image->surface);
    cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
    gdk_cairo_set_source_pixbuf(cr, image->pbuf, 0, 0);
    cairo_paint(cr);
    cairo_destroy(cr);
    
    add_layer(image->layer);

    return TRUE;
}
Example #14
0
int DXF::add_vertex(void)
{
  if(curVLayer[0] == '\0')
    return -1;
  
  Layer *layer = get_layer(curVLayer);
  if(!layer) {
    create_current_layer(curVLayer);
    add_layer();
    layer = curLayer;
  }
  if(layer->nVertices == 0)
    layer->vertices = (Vector *)malloc(sizeof(Vector)*VALLOC);
  else if(layer->nVertices % VALLOC == 0)
    layer->vertices = (Vector *)
        realloc(layer->vertices,sizeof(Vector)*(layer->nVertices+VALLOC));
  
  memcpy(layer->vertices[layer->nVertices++],curVertex,sizeof(Vector));
  
  return 0;
} // end of add_vertex 
Example #15
0
int DXF::add_facetidx(void)
{
  if(curVLayer[0] == '\0')
    return -1;
  
  Layer *layer = get_layer(curVLayer);
  if(!layer) {
    create_current_layer(curVLayer);
    add_layer();
    layer = curLayer;
  }
  
  if(layer->nFacetIdx == 0)
    layer->facetIdx = (FacetIdx *)malloc(sizeof(FacetIdx)*FALLOC);
  else if(layer->nFacetIdx%FALLOC == 0)
    layer->facetIdx = (FacetIdx *)
        realloc(layer->facetIdx,sizeof(FacetIdx)*(layer->nFacetIdx+FALLOC));
  
  memcpy(layer->facetIdx[layer->nFacetIdx++],curFacetIdx,sizeof(FacetIdx));
  
  return 0;
} // end of add_facetidx
Example #16
0
   Tilemap::Tilemap(const std::string& path) : dir(Utils::basedir(path))
   {
      xml_document doc;
      if (!doc.load_file(path.c_str()))
         throw std::runtime_error(Utils::join("Failed to load XML map: ", path, "."));

      xml_node map   = doc.child("map");
      width      = map.attribute("width").as_int();
      height     = map.attribute("height").as_int();
      tilewidth  = map.attribute("tilewidth").as_int();
      tileheight = map.attribute("tileheight").as_int();

      if (!width || !height || !tilewidth || !tileheight)
         throw std::logic_error("Tilemap is malformed.");

      std::map<unsigned, Surface> tiles;
      for (auto set = map.child("tileset"); set; set = set.next_sibling("tileset"))
         add_tileset(tiles, set);

      for (auto layer = map.child("layer"); layer; layer = layer.next_sibling("layer"))
         add_layer(tiles, layer, tilewidth, tileheight);
   }
Example #17
0
void model_profile(model *m, profile *p)
{
  int layer, repeat_start, R, R_start, R_end, R_count;

  profile_reset(p);

  /* Insert vacuum layers */
  if (!profile_extend(p,1)) return;
  profile_slice(p,10.,m->rho[0],m->mu[0]
#ifdef HAVE_MAGNETIC
		,m->P[0],m->theta[0]
#endif
		);
  add_interface_left(m,p,0,1);
  p->vacuum_offset = profile_depth(p); /* vacuum interface thickness */

  /* initialize R_start, R_end, R_count */
  model_repeat(m,R=0,&R_start,&R_end,&R_count);

  repeat_start = -1;
  for (layer=1; layer<m->n-1; layer++) {
    /* Remember where the repeat section starts */
    if (layer == R_start+1) repeat_start = p->n;

    /* Check if we need to repeat */
    if (layer == R_end) {
      /* The interface between repeats is different from the
       * interface into the first repeat and out of the last
       * repeat. So instead of repeating R1 R2 R3 R4 as in:
       *       Ln|R1 R2 R3 R4|R1 R2 R3 R4|R1 R2 R3 R4|Ln+1
       * we have to repeat R2 R3 R1 as in:
       *       Ln R1*|R2 R3 R4 R1|R2 R3 R4 R1|R2 R3 R4* Ln+1
       * with the last repeat only extending from R_start+1 to
       * R_end-1.
       *
       * At this point we have:
       *       Ln R1*|R2 R3
       * so we need to add R4 and R1 to complete the repeating
       * section, then copy that section R_count-2 times (first
       * repeat is done, last repeat is special), then copy
       * what we have of the last repeat, leaving us at:
       *       Ln R1* R2 R3 R4 R1 R2 R3 R4 R1 R2 R3
       * and layer == R4, so continue as normal. */
      int r, repeat_length, repeat_interface;

      repeat_interface = p->n;

      /* add interface between repeating sections */
      add_layer(m,p,R_end-1,R_end,R_start);
      add_layer(m,p,R_end,R_start,R_start+1);

      /* do bulk repeats of R_start+1 to R_start */
      assert(repeat_start > 0);
      repeat_length = p->n - repeat_start;
      profile_extend(p,R_count*repeat_length); /* make sure there is room */
      for (r=1; r < R_count-1; r++)
	profile_copy(p, repeat_start, repeat_length);

      /* copy layers from R_start to I_start */
      profile_copy(p, repeat_start, repeat_interface-repeat_start);

      /* Look for next repeat */
      model_repeat(m,++R,&R_start,&R_end,&R_count);
      repeat_start = -1;
    }
    add_layer(m,p,layer-1,layer,layer+1);
  }

  /* Insert substrate layers */
  add_interface_right(m,p,layer-1,layer);
  if (!profile_extend(p,1)) return;
  profile_slice(p,10.,m->rho[layer],m->mu[layer]
#ifdef HAVE_MAGNETIC
		,m->P[layer],m->theta[layer]
#endif
		);

  /* Convert polar to cartesian for magnetic layers */
  profile_expth(p);
}
Example #18
0
Medial_explore_3::Medial_explore_3() : has_topology_filtration(false), has_sheets(false), has_mat(false), has_balls(false) {
	GL_draw_layer_3* faces_layer = new Medial_surface_layer_3("Medial faces",this, "Faces in the medial surface", false, false, false);
	add_layer(faces_layer);
	GL_draw_layer_3* edges_layer = new Medial_surface_layer_3("Medial edges",this, "Edges in the medial surface", true, false, false);
	add_layer(edges_layer);

	GL_draw_layer_3* niv_layer = new Medial_surface_layer_3("Medial vertices",this, "Vertices detected as not interior", false, true, false);
	add_layer(niv_layer);

	GL_draw_layer_3* an_layer = new Medial_surface_layer_3("Angle faces",this, "Angle filtered faces in the medial surface", false, false, true, false);
	add_layer(an_layer);
	GL_draw_layer_3* la_layer = new Medial_surface_layer_3("Lambda faces",this, "Lambda filtered faces in the medial surface", false, false, false, false, false, false, false, false, true);
	add_layer(la_layer);
	GL_draw_layer_3* tan_layer = new Medial_surface_layer_3("Top angle faces",this, "Topology angle filtered faces in the medial surface", false, false, false, true);
	add_layer(tan_layer);

	GL_draw_layer_3* fr_layer = new Medial_surface_layer_3("Front faces",this, "Topology angle filtered faces in the medial surface", false, false, false, false, true);
	add_layer(fr_layer);
	GL_draw_layer_3* vis_layer = new Medial_surface_layer_3("Visited faces",this, "Topology angle filtered faces in the medial surface", false, false, false, false, false, true);
	add_layer(vis_layer);
	GL_draw_layer_3* visn_layer = new Medial_surface_layer_3("Left faces",this, "Topology angle filtered faces in the medial surface", false, false, false, false, false, true, true);
	add_layer(visn_layer);

	GL_draw_layer_3* scale_balls_layer = new Medial_surface_layer_3("Dense scale axis balls",this, "Finite set of balls approximating the scale axis", false, false, false, false, false, false, false, true);
	add_layer(scale_balls_layer);

	GL_draw_layer_3* lambda_balls_layer = new Medial_surface_layer_3("Dense lambda balls",this, "Finite set of balls approximating the scale axis", false, false, false, false, false, false, false, true, true);
	add_layer(lambda_balls_layer);
	GL_draw_layer_3* angle_balls_layer = new Medial_surface_layer_3("Dense angle balls",this, "Finite set of balls approximating the scale axis", false, false, true, false, false, false, false, true);
	add_layer(angle_balls_layer);
	GL_draw_layer_3* topangle_balls_layer = new Medial_surface_layer_3("Dense topangle balls",this, "Finite set of balls approximating the scale axis", false, false, false, true, false, false, false, true);
	add_layer(topangle_balls_layer);


	// medial sheets
	GL_draw_layer_3* med_sheets_layer = new Medial_sheets_layer_3("Medial sheets",this, "Medial sheets segmented by rim and seam points", false);
	add_layer(med_sheets_layer);
	GL_draw_layer_3* med_sheets_wf_layer = new Medial_sheets_layer_3("Medial wireframes",this, "The wireframe of sheets", true);
	add_layer(med_sheets_wf_layer);

	GL_draw_layer_3* med_topa_sheets_layer = new Medial_sheets_layer_3("Medial topangle sheets",this, "Medial sheets filtered by topology preserving angle filtration", false, false, false, true);
	add_layer(med_topa_sheets_layer);
	

	GL_draw_layer_3* med_vert_sheets_layer = new Medial_sheets_layer_3("Medial sheets vertices",this, "Medial sheets vertices, currently misused for finding boundary vertices", false, true, false, true);
	add_layer(med_vert_sheets_layer);

	Application_settings::add_int_setting("medial-explore-front-steps",1);
	Application_settings::add_bool_setting("debug-medial-explore-front", false);

	Application_settings::add_int_setting("medial-explore-sheet-front-steps",1);
	Application_settings::add_bool_setting("debug-medial-explore-sheet-front", false);

	Application_settings::add_double_setting("scale-axis-balls-center-max-distance",0.000000001, "Minimum squared distance between centers as of balls before they'll be considered duplicate -- relative to bounding diagonal");
	Application_settings::add_double_setting("scale-axis-balls-min-intersection-depth",140, "Minimum intersection depth of two balls connected by a segment -- otherwise triangle will be subdivided into 4");

	Application_settings::add_double_setting("angle-limit",10);
	Application_settings::add_double_setting("lambda-limit",0);

	Application_settings::add_int_setting("medial-surface-boundary-smoothing-steps", 0);
	Application_settings::add_int_setting("scale-surface-boundary-smoothing-steps", 0);
	Application_settings::add_double_setting("boundary-smoothing-neighbor-edge-max-squared-ratio",10);
	Application_settings::add_double_setting("boundary-smoothing-max-vertex-movement",0.05);

}
Example #19
0
void gilviewer_frame::AddLayer(const layer::ptrLayerType &layer)
{
    m_panelviewer->add_layer(layer);
}
Example #20
0
void NeuralNet::load(std::istream& is)
{
    layers.clear();
    NNLayer l(1, 1, linear_func);
    while (is >> l) add_layer(l);
}
Example #21
0
int
main(int ac, char ** av)
{
  object * old = &oct,         /* Default is octahedron */
    * newobj;
  int ccwflag = 1,        /* Reverse vertex order if true */
    i,
    level,              /* Current subdivision level */
    maxlevel = 0;       /* Maximum subdivision level */

  int useblock = 0;

  char * outfile = NULL;
  
  /* Parse arguments */
  for (i = 1; i < ac; i++) {
    if (!strcmp(av[i], "-c"))
      ccwflag = 1;
    else if (!strcmp(av[i], "-t"))
      old = &tet;
    else if (!strcmp(av[i], "-i"))
      old = &ico;
    else if (!strcmp(av[i], "-b"))
      useblock = 1;
    else if (!strcmp(av[i], "-o") && i < ac-1) {
      outfile = av[i+1];
      i++;
    }
    else if (isdigit(av[i][0])) {
      if ((maxlevel = atoi(av[i])) < 1) {
	fprintf(stderr, "dxfsphere: # of levels must be >= 1\n");
	exit(1);
      }
    } 
    else {
      break;
    }
  }
  
  if (i < ac || ac == 1) {
    fprintf(stderr, "dxfsphere: [-c] [-t] [-i] [-b] [-o <outfile>] <levels>\n");
    exit(1);
  }

  // DIME: initialize output file
  dimeOutput out;
  if (!outfile || !out.setFilename(outfile)) {
    out.setFileHandle(stdout);
  }
  // DIME: create dime model
  dimeModel model;

  // DIME: only needed if you need your object to be in a layer
  {
    // DIME: add tables section (needed for layers).
    dimeTablesSection * tables = new dimeTablesSection;
    model.insertSection(tables);
    
    // DIME: set up a layer table to store our layers
    dimeTable * layers = new dimeTable(NULL);
    
    // DIME: set up our layers
    add_layer(LAYERNAME1, 16, &model, layers);
    add_layer(LAYERNAME2, 8, &model, layers);

    // DIME: insert the layer in the table
    tables->insertTable(layers); 
  }

  // DIME: only needed if you want to create the sphere as a BLOCK
  dimeBlock * block = NULL;
  if (useblock) {
    dimeBlocksSection * blocks = new dimeBlocksSection;
    model.insertSection(blocks);
    block = new dimeBlock(NULL);
    block->setName("MyBlock");
    blocks->insertBlock(block);
  }

  // DIME: add the entities section.
  dimeEntitiesSection * entities = new dimeEntitiesSection;
  model.insertSection(entities);

  if (ccwflag)
    flip_object(old);
  
  /* Subdivide each starting triangle (maxlevel - 1) times */
  for (level = 1; level < maxlevel; level++) {
    /* Allocate a new object */
    /* FIXME: Valgrind reports an 8-byte memory leak here. 20030404 mortene. */
    newobj = (object *)malloc(sizeof(object));
    if (newobj == NULL) {
      fprintf(stderr, "%s: Out of memory on subdivision level %d\n",
              av[0], level);
      exit(1);
    }
    newobj->npoly = old->npoly * 4;
    
    /* Allocate 4* the number of points in the current approximation */
    newobj->poly  = (triangle *)malloc(newobj->npoly * sizeof(triangle));
    if (newobj->poly == NULL) {
      fprintf(stderr, "%s: Out of memory on subdivision level %d\n",
              av[0], level);
      exit(1);
    }
      
    /* Subdivide each triangle in the old approximation and normalize
     *  the new points thus generated to lie on the surface of the unit
     *  sphere.
     * Each input triangle with vertices labelled [0,1,2] as shown
     *  below will be turned into four new triangles:
     *
     *                      Make new points
     *                          a = (0+2)/2
     *                          b = (0+1)/2
     *                          c = (1+2)/2
     *        1
     *       /\             Normalize a, b, c
     *      /  \
     *    b/____\ c         Construct new triangles
     *    /\    /\              [0,b,a]
     *   /  \  /  \             [b,1,c]
     *  /____\/____\            [a,b,c]
     * 0      a     2           [a,c,2]
     */
    for (i = 0; i < old->npoly; i++) {
      triangle
        *oldt = &old->poly[i],
        *newt = &newobj->poly[i*4];
      point a, b, c;
      
      a = *normalize(midpoint(&oldt->pt[0], &oldt->pt[2]));
      b = *normalize(midpoint(&oldt->pt[0], &oldt->pt[1]));
      c = *normalize(midpoint(&oldt->pt[1], &oldt->pt[2]));
        
      newt->pt[0] = oldt->pt[0];
      newt->pt[1] = b;
      newt->pt[2] = a;
      newt++;
        
      newt->pt[0] = b;
      newt->pt[1] = oldt->pt[1];
      newt->pt[2] = c;
      newt++;
      
      newt->pt[0] = a;
      newt->pt[1] = b;
      newt->pt[2] = c;
      newt++;
      
      newt->pt[0] = a;
      newt->pt[1] = c;
      newt->pt[2] = oldt->pt[2];
    }
    
    if (level > 1) {
      free(old->poly);
      free(old);
    }
    
    /* Continue subdividing new triangles */
    old = newobj;
  }
  
  /* Print out resulting approximation */
  print_object(old, maxlevel, model, LAYERNAME1, block);

  if (block) {
    dimeInsert * insert = new dimeInsert;
    insert->setBlock(block);
    model.addEntity(insert);
  }

  // DIME: write the model to file
  model.write(&out);

  return 0;
}
Example #22
0
int DXF::face3dFunc(int token, char *line)
{
  char *s;
  switch(token) {
    case 2:
    case 8:      char name[64];
      memset(name,0,64);
      s = line;
      while(*s == ' ' || *s == '\t') *s++;
      for(unsigned int i=0;i<strlen(s);i++) {
        if(s[i] == ' ' || s[i] == '\t') break;
        name[i] = s[i];
      }
      curLayer = get_layer(name);
      if(!curLayer) {
        create_current_layer(name);
        add_layer();
      }
      break;
    case 10:
      curFacet[0][0] = (float) atof(line);
      break;
    case 20:
      curFacet[0][1] = (float) atof(line);
      break;
    case 30:
      curFacet[0][2] = (float) atof(line);
      break;
    case 11:
      curFacet[1][0] = (float) atof(line);
      break;
    case 21:
      curFacet[1][1] = (float) atof(line);
      break;
    case 31:
      curFacet[1][2] = (float) atof(line);
      break;
    case 12:
      curFacet[2][0] = (float) atof(line);
      break;
    case 22:
      curFacet[2][1] = (float) atof(line);
      break;
    case 32:
      curFacet[2][2] = (float) atof(line);
      break;
    case 13:
      curFacet[3][0] = (float) atof(line);
      break;
    case 23:
      curFacet[3][1] = (float) atof(line);
      break;
    case 33:
      curFacet[3][2] = (float) atof(line);
      break;

   default:
      break;
  }
  return 0;
} // end of face3dFunc
void sample_vector_layer_viewer::add_layer(const layer::ptrLayerType &layer) {
        m_drawPane->add_layer(layer);
}
Example #24
0
int DXF::layerEndFunc(void)
{
  if(add_layer()) return -1;
  curLayer = (Layer *)0;
  return 0;
} // end of layerEndFunc
Example #25
0
Mesh_view_3::Mesh_view_3() : Geometry(), has_domain_mesh(false), has_mesh_balls(false), has_mesh_polar_triangulation(false) {
	// input surface mesh
	GL_draw_layer_3* mesh_layer = new Mesh_layer_3("Input mesh",this, "Mesh of the file read from the OFF file", false, false);
	add_layer(mesh_layer);
	GL_draw_layer_3* wireframe_layer = new Mesh_layer_3("Input wireframe",this, "Wireframe of the file read from the OFF file", true, false);
	add_layer(wireframe_layer);
	GL_draw_layer_3* point_layer = new Mesh_layer_3("Input vertices",this, "Points in the file read from the OFF file", true, true);
	add_layer(point_layer);
	GL_draw_layer_3* faces_layer = new Mesh_layer_3("Input faces",this, "Faces in the file read from the OFF file", true, false, true);
	add_layer(faces_layer);

	// meshed surface
	GL_draw_layer_3* surf_mesh_layer = new Domain_mesh_layer_3("Surface remesh",this, "Mesh of the surface after volume meshing this shape", false, true);
	add_layer(surf_mesh_layer);
	GL_draw_layer_3* surfw_mesh_layer = new Domain_mesh_layer_3("Surface remesh edges",this, "Wireframe of the surface after volume meshing this shape", true, true);
	add_layer(surfw_mesh_layer);

	GL_draw_layer_3* vol_mesh_layer = new Domain_mesh_layer_3("Volume remesh",this, "Mesh of the volume after volume meshing this shape", false, false);
	add_layer(vol_mesh_layer);
	GL_draw_layer_3* volw_mesh_layer = new Domain_mesh_layer_3("Volume remesh edges",this, "Wireframe of the volume after volume meshing this shape", true, false);
	add_layer(volw_mesh_layer);

	GL_draw_layer_3* ball_mesh_layer = new Domain_mesh_layer_3("Mesh balls",this, "Circumscribed balls of the tets in volume mesh - surface", false, false, true);
	add_layer(ball_mesh_layer);
	GL_draw_layer_3* ballw_mesh_layer = new Domain_mesh_layer_3("Mesh spheres",this, "Circumscribed balls of the tets in volume mesh - wireframe", true, false, true);
	add_layer(ballw_mesh_layer);

	// Mesh polar triangulation
	GL_draw_layer_3* poi_mesh_layer = new Mesh_polar_triangulation_layer_3("Surface points",this, "Surface samples of the volume meshing", false, false, true);
	add_layer(poi_mesh_layer);
	GL_draw_layer_3* sd_mesh_layer = new Mesh_polar_triangulation_layer_3("Surface Delaunay",this, "Delaunay of the surface samples from the volume meshing", true, false, false);
	add_layer(sd_mesh_layer);

	GL_draw_layer_3* mpb_mesh_layer = new Mesh_polar_triangulation_layer_3("Mesh polar balls",this, "Polar balls defined based on mesh", false, true, false);
	add_layer(mpb_mesh_layer);
	



	Application_settings::add_double_setting("meshing-surface-angle", 25);
	Application_settings::add_double_setting("meshing-surface-size", 0.15);
	Application_settings::add_double_setting("meshing-surface-approximation", 0.008);

	Application_settings::add_double_setting("meshing-tet-radius-edge-ratio", 4);
	Application_settings::add_double_setting("meshing-tet-size", 0.1);

	Application_settings::add_bool_setting("ignore-mesh-balls-centered-outside", true);
}