void c_private_show_image_from_ref(OBJ_PTR fmkr, FM *p, int ref, double llx, double lly, double lrx, double lry, double ulx, double uly, int *ierr) { if (constructing_path) { RAISE_ERROR("Sorry: must finish with current path before calling " "show_image", ierr); return; } double a, b, c, d, e, f; // the transform to position the image int xo_num = Find_XObjRef(ref); if(xo_num < 0) { RAISE_ERROR_i("Could not find image PDF object %d", ref, ierr); return; } llx = convert_figure_to_output_x(p, llx); lly = convert_figure_to_output_y(p, lly); lrx = convert_figure_to_output_x(p, lrx); lry = convert_figure_to_output_y(p, lry); ulx = convert_figure_to_output_x(p, ulx); uly = convert_figure_to_output_y(p, uly); Create_Transform_from_Points(llx, lly, lrx, lry, ulx, uly, &a, &b, &c, &d, &e, &f); fprintf(TF, "q %0.2f %0.2f %0.2f %0.2f %0.2f %0.2f cm /XObj%i Do Q\n", a, b, c, d, e, f, xo_num); update_bbox(p, llx, lly); update_bbox(p, lrx, lry); update_bbox(p, ulx, uly); update_bbox(p, lrx+ulx-llx, lry+uly-lly); }
void rotate_atoms(double *axis, double phi, Boolean store_g, Boolean rot_subset) { void adjust_current_frame(void); void canvas_cb(Widget, XtPointer, XtPointer); void clear_message_area (void); void deactivate_region(void); void normalize_vec(double *); void rotate(double *); void rotate_vectors(double *, double); void set_rotate_axis(double *); void set_rotate_angle(double); void set_rotate_origin(double *); void store_coords(void); void update_bbox(void); void update_bond_matrix(Boolean); void update_lengths_dialog(Boolean); void vector_product(double *, double *, double *); int i,all_rotated; double local_com[3], local_mass; double atom_coords[3]; all_rotated = 1; local_com[0] = local_com[1] = local_com[2] = 0; local_mass = 0; changing_frame = False; if((rotate_about == ROTATE_ABOUT_ORIGIN) || changing_frame) { set_rotate_origin(NULL); for(i = 0; i < no_atoms; i++) { if(atoms[i].edit == 0) { all_rotated = 0; atoms_sorted = 0; /* Depths have changed */ } } } else if(rotate_about == ROTATE_ABOUT_LOCAL_COM) { for(i = 0; i < no_atoms; i++) { if(atoms[i].edit == 1) { local_com[0] += atoms[i].mass * atoms[i].x; local_com[1] += atoms[i].mass * atoms[i].y; local_com[2] += atoms[i].mass * atoms[i].z; local_mass += atoms[i].mass; } else { all_rotated = 0; atoms_sorted = 0; /* Depths have changed */ } } for(i = 0; i < 3; i++) { if (local_mass == 0) { /* All dummy atoms? */ local_com[i] = 0; } else { local_com[i] /= local_mass; } } set_rotate_origin(local_com); } set_rotate_axis(axis); set_rotate_angle(phi); for(i = 0; i < no_atoms; i++) { if((atoms[i].edit == 1) || (rot_subset == 0)) { atom_coords[0] = atoms[i].x; atom_coords[1] = atoms[i].y; atom_coords[2] = atoms[i].z; rotate(atom_coords); atoms[i].x = atom_coords[0]; atoms[i].y = atom_coords[1]; atoms[i].z = atom_coords[2]; } } if (bbox_available) { for (i = 0; i < 8; i++) { rotate (file_bbox.v[i]); } } if(store_g && all_rotated){ /* modify global vectors describing current orientation of frame */ set_rotate_origin(NULL); for(i=0;i<3;i++){ rotate(global_matrix[i]); } } if(!all_rotated){ update_bond_matrix(True); } rotate_vectors(axis, phi); update_bbox (); deactivate_region(); clear_message_area (); canvas_cb(canvas,NULL,NULL); update_lengths_dialog(False); }
//==== Generate Fuse Component ====// void PropGeom::generate() { int i, j; //==== Copy Current Section Data into SectVec ====// sectVec[currSectID].chord = chord(); sectVec[currSectID].twist = twist(); sectVec[currSectID].x_off = loc(); sectVec[currSectID].y_off = offset(); Xsec_surf surf; surf.set_num_pnts( numPnts.iget() ); surf.set_num_xsecs( sectVec.size()+2 ); //==== Load Up Airfoil ====// for ( int ip = 0 ; ip < surf.get_num_pnts() ; ip++ ) surf.set_pnt(0, ip, sectVec[0].foil->get_end_cap(ip) ); int numxs = sectVec.size(); for ( i = 0 ; i < numxs ; i++ ) { for ( j = 0 ; j < surf.get_num_pnts() ; j++ ) { surf.set_pnt( i+1, j, sectVec[i].foil->get_pnt(j) ); } } for ( int ip = 0 ; ip < surf.get_num_pnts() ; ip++ ) surf.set_pnt(numxs+1, ip, sectVec[numxs-1].foil->get_end_cap(ip) ); //==== Build Up One Blade ====// double rad = diameter()/2.0; for ( i = 0 ; i < surf.get_num_xsecs() ; i++ ) { int sid = i; if ( i > 0 ) sid = i-1; if ( i > (int)sectVec.size()-1 ) sid = (int)sectVec.size()-1; Section* sPtr = &(sectVec[sid]); surf.scale_xsec_x( i, sPtr->chord()*rad ); surf.scale_xsec_z( i, sPtr->chord()*rad ); surf.offset_xsec_x( i, -0.5*(sPtr->chord()*rad) ); surf.rotate_xsec_y( i, 90.0 ); surf.rotate_xsec_y( i, -sPtr->twist() - pitch() ); surf.offset_xsec_y( i, sPtr->x_off()*rad ); surf.offset_xsec_z( i, -sPtr->y_off()*rad ); } //==== Set Flags So Trailing Edge Remains Sharp ====// surf.set_pnt_tan_flag( 0, Bezier_curve::SHARP ); surf.set_pnt_tan_flag( 1, Bezier_curve::SHARP ); int num_pnts = surf.get_num_pnts(); surf.set_pnt_tan_flag( num_pnts-1, Bezier_curve::SHARP ); if ( !smoothFlag ) { for ( i = 0 ; i < surf.get_num_xsecs() ; i++ ) { surf.set_xsec_tan_flag( i, Bezier_curve::SHARP ); } } else // Sharpen End Caps { surf.set_xsec_tan_flag( surf.get_num_xsecs()-2, Bezier_curve::SHARP ); } bezier_surf besurf; surf.load_bezier_surface( &besurf ); int umax = besurf.get_u_max(); int wmax = besurf.get_w_max(); Xsec_surf smooth_surf; smooth_surf.set_num_pnts( (surf.get_num_pnts()-1)*numW + 1 ); smooth_surf.set_num_xsecs( (surf.get_num_xsecs()-1)*numU + 1 ); for ( i = 0 ; i < smooth_surf.get_num_xsecs() ; i++ ) { double fu = (double)i/(double)(smooth_surf.get_num_xsecs()-1); double u = fu*(double)umax; for ( j = 0 ; j < smooth_surf.get_num_pnts() ; j++ ) { double fw = (double)j/(double)(smooth_surf.get_num_pnts()-1); double w = fw*(double)wmax; vec3d p = besurf.comp_pnt( u, w ); smooth_surf.set_pnt( i, j, p ); } } //==== Load Blades into bladeVec ====// for ( int nb = 0 ; nb < (int)bladeVec.size() ; nb++ ) { bladeVec[nb].set_num_pnts( smooth_surf.get_num_pnts() ); bladeVec[nb].set_num_xsecs( smooth_surf.get_num_xsecs() ); //==== Load Points ====// for ( i = 0 ; i < smooth_surf.get_num_xsecs() ; i++ ) for ( j = 0 ; j < smooth_surf.get_num_pnts() ; j++ ) bladeVec[nb].set_pnt( i, j, smooth_surf.get_pnt( i, j ) ); double xang = 360.0*(double)nb/(double)(bladeVec.size()); for ( i = 0 ; i < bladeVec[nb].get_num_xsecs() ; i++ ) { bladeVec[nb].rotate_xsec_z( i, cone_angle() ); bladeVec[nb].rotate_xsec_x( i, xang ); } bladeVec[nb].load_refl_pnts_xsecs(); bladeVec[nb].load_hidden_surf(); bladeVec[nb].load_normals(); bladeVec[nb].load_uw(); } for ( int i = 0 ; i < (int)sectVec.size() ; i++ ) sectVec[i].SetGeomPtr( this ); update_bbox(); }
//=========================================== //TextContent //=========================================== void ImageContent::init(const TiXmlElement* root) { string name = root->ValueStr(); if (name == "Image") { string left_name = root->Attribute("filename"); left_name = Story::resolve_rel_path(left_name); try { left = the_app.tex_mgr.loadTexture(left_name); if (left.isNull()) { msgBox("Image file \"" + left_name + "\" was not found"); return; } } catch (GImage::Error& err) { left = NULL; msgBox("Image file \"" + left_name + "\" is invalid and could not be loaded"); return; } is_stereo = false; width = left->texelWidth(); height = left->texelHeight(); } else if (name == "StereoImage") { string left_name = root->Attribute("left-image"); left_name = Story::resolve_rel_path(left_name); try { left = the_app.tex_mgr.loadTexture(left_name); if (left.isNull()) { msgBox("Image file \"" + left_name + "\" was not found"); return; } } catch (GImage::Error& err) { left = NULL; msgBox("Image file \"" + left_name + "\" is invalid and could not be loaded"); return; } width = left->texelWidth(); height = left->texelHeight(); string right_name = root->Attribute("right-image"); right_name = Story::resolve_rel_path(right_name); try { right = the_app.tex_mgr.loadTexture(right_name); if (right.isNull()) { msgBox("Image file \"" + right_name + "\" was not found"); return; } } catch (GImage::Error& err) { right = NULL; msgBox("Image file \"" + right_name + "\" is invalid and could not be loaded"); return; } is_stereo = true; if (right->texelWidth() != width) { msgBox("Width of \"" + left_name + "\" does not match width of \"" + right_name + "\".\nThe widths of left and right image must be the same"); return; } if (right->texelHeight() != height) { msgBox("Height of \"" + left_name + "\" does not match height of \"" + right_name + "\".\nThe heights of left and right image must be the same"); return; } } else { alwaysAssertM(0, "Invalid Image Element"); } //scale height to image proportions height_ratio = height / width; //scale *= 2.f; float max_scale = 1.f; if (height > width) { width *= (max_scale / height); height = max_scale; } else { height *= (max_scale / width); width = max_scale; } // float width = scale; // float height = height_ratio * scale; float min_x = -width * .5; float max_x = width * .5; float min_y = -height * .5; float max_y = height * .5; local_bbox.set(Vector3(min_x, min_y, 0), Vector3(max_x, max_y, 0.02)); update_bbox(); verts.append(Vector3(min_x, max_y, 0)); verts.append(Vector3(min_x, min_y, 0)); verts.append(Vector3(max_x, min_y, 0)); verts.append(Vector3(max_x, max_y, 0)); coords.append(Vector2(0, 0)); coords.append(Vector2(0, 1)); coords.append(Vector2(1, 1)); coords.append(Vector2(1, 0)); valid = true; }