ScaleBarObject ScaleBarGrabber::scalebar() { ScaleBarObject so; so.set(position(), voxels(), type(), textpos()); return so; }
RemoteInformation deserializeDataSourceData( const ::zeq::Event& event ) { if( event.getType() != EVENT_DATASOURCE_DATA ) return RemoteInformation(); auto data = GetVolumeInformation( event.getData( )); RemoteInformation info; livre::VolumeInformation& vi = info.second; info.first.low() = data->eventLow(); info.first.high() = data->eventHigh(); vi.isBigEndian = data->isBigEndian(); vi.compCount = data->compCount(); vi.dataType = DataType( data->dataType( )); vi.overlap = _deserializeVector3< unsigned >( data->overlap( )); vi.maximumBlockSize = _deserializeVector3< unsigned >( data->maximumBlockSize( )); vi.minPos = _deserializeVector3< float >( data->minPos( )); vi.maxPos = _deserializeVector3< float >( data->maxPos( )); vi.voxels = _deserializeVector3< unsigned >( data->voxels( )); vi.worldSize = _deserializeVector3< float >( data->worldSize( )); vi.boundingBox.getMin() = _deserializeVector3< float >( data->boundingBoxMin( )); vi.boundingBox.getMax() = _deserializeVector3< float >( data->boundingBoxMax( )); vi.worldSpacePerVoxel = data->worldSpacePerVoxel(); const Vector3ui& blockSize = vi.maximumBlockSize - vi.overlap * 2; Vector3ui blocksSize = vi.voxels / blockSize; blocksSize = blocksSize / ( 1u << data->depth( )); vi.rootNode = RootNode( data->depth(), blocksSize ); return info; }
// Retun the value for normalizing the mesh criteria double Vol2mesh :: get_normalize_value(){ double N = 1; if (normalize_){ vector<double> v = voxels(); N = (v[0] + v[1] + v[2]) / 3; } return N; }
bool VoxelsIOPlugin::save(const QString &formatName, const QString &fileName, MeshModel &m, const int mask,const RichParameterSet & par, vcg::CallBackPos *cb, QWidget *parent) { // TODO Add error messages vcg::tri::UpdatePosition< CMeshO >::Scale ( m.cm, static_cast< CMeshO::ScalarType >( rasterization_scale ) ); vcg::tri::UpdateBounding< CMeshO >::Box( m.cm ); init_voxmap_size( m ); QScopedArrayPointer< unsigned char > voxels( rasterize( this, m ) ); QString nrrd; if( !voxels || (nrrd = write_nrrd( voxels.data() )).isEmpty() || !(voxels.reset( resample( nrrd )), voxels) || !write_tiles( voxels.data(), fileName ) ) return false; QFile header( fileName.endsWith( ".voxels" ) ? fileName.left( fileName.length() - QString( ".voxels" ).length() ) : fileName + ".header" ); if( !header.open( QIODevice::WriteOnly ) ) return false; QTextStream str( &header ); str << ";;; -*- lisp -*-\n(size " << voxmap_size.X() << " " << voxmap_size.Y() << " " << voxmap_size.Z() << ")\n(voxels . \"" << fileName << "\")\n"; return true; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Coordinate is a struct of x,y,z // component is the model to calculate the PCA for // eVectors are the eigen vectors and values for the three axes // the longest axis is in eVectors[0] void PCA(vector<Coordinate> &component, vector<Coordinate> &eVectors, vector<float> &eValues){ int i,j,k; /* //find the boundary voxels vector<Coordinate>voxels; for (i=0; i<component.size(); i++){ int cntr=0; for (j=0; j<component.size(); j++){ if (getDistance(component[i], component[j])<1.05) cntr++; } if (cntr<7 && cntr>3) voxels.push_back(component[i]); } */ vector<Coordinate>voxels (component); //cout<<endl<<"Number of boundary voxels: "<<voxels.size()<<endl; //calculate the centroid Coordinate centroid = getCentroid(voxels); vector<Coordinate> newVoxels (voxels.size()); float covXX=0.0, covYY=0.0, covZZ=0.0, covXY=0.0, covXZ=0.0, covYZ=0.0; for (i=0; i<voxels.size(); i++){ newVoxels[i].x = voxels[i].x-centroid.x; newVoxels[i].y = voxels[i].y-centroid.y; newVoxels[i].z = voxels[i].z-centroid.z; covXX += newVoxels[i].x*newVoxels[i].x; covYY += newVoxels[i].y*newVoxels[i].y; covZZ += newVoxels[i].z*newVoxels[i].z; covXY += newVoxels[i].x*newVoxels[i].y; covXZ += newVoxels[i].x*newVoxels[i].z; covYZ += newVoxels[i].y*newVoxels[i].z; } covXX /= voxels.size()-1; covYY /= voxels.size()-1; covZZ /= voxels.size()-1; covXY /= voxels.size()-1; covXZ /= voxels.size()-1; covYZ /= voxels.size()-1; vector<vector<float> > covMatrix(3, vector<float> (3)); covMatrix[0][0] = covXX; covMatrix[0][1] = covXY; covMatrix[0][2] = covXZ; covMatrix[1][0] = covXY; covMatrix[1][1] = covYY; covMatrix[1][2] = covYZ; covMatrix[2][0] = covXZ; covMatrix[2][1] = covYZ; covMatrix[2][2] = covZZ; /* //print covMatrix cout<<"covMatrix: "<<endl; for (i=0; i<3; i++){ for (j=0; j<3; j++) cout<<covMatrix[i][j]<<" "; cout<<endl; } */ Jacobi J; J.matrix.resize(3); for (i=0; i<3; i++) J.matrix[i].resize(3); J.matrix = covMatrix; J.dimen = 3; J.eigenvalues.resize(J.dimen); J.eigenvectors.resize(J.dimen); J.e = 1e-8; J.jacobi(); eValues.clear(); eValues.resize(3); eVectors.clear(); eVectors.resize(3); vector<vector<float> > Evector(3, vector<float> (3)); eValues = J.getEigenvalues(); Evector = J.getEigenvectors(); for (i=0; i<3; i++){ eVectors[i].x = Evector[i][0]; eVectors[i].y = Evector[i][1]; eVectors[i].z = Evector[i][2]; } //cout<<endl<<"PCA..."<<endl; //J.printEigen(); }
//------------------------------------------------------------------------------ bool OBOpenDXCubeFormat::ReadMolecule( OBBase* pOb, OBConversion* pConv ) { OBMol* pmol = pOb->CastAndClear<OBMol>(); if(pmol == 0) return false; istream& ifs = *pConv->GetInStream(); const char* title = pConv->GetTitle(); char buffer[BUFF_SIZE]; stringstream errorMsg; if (!ifs) return false; // We are attempting to read past the end of the file pmol->SetTitle(title); while (ifs.good() && ifs.getline(buffer,BUFF_SIZE)) { if (buffer[0] == '#') continue; // comment line if (EQn(buffer, "object", 6)) break; } if (!ifs) return false; // ran out of lines vector<string> vs; tokenize(vs, buffer); // Number of grid points (voxels) vector<int> voxels(3); if (!EQn(buffer, "object", 6) || vs.size() != 8) return false; else { voxels[0] = atoi(vs[5].c_str()); voxels[1] = atoi(vs[6].c_str()); voxels[2] = atoi(vs[7].c_str()); } double x, y, z; if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "origin", 6)) return false; else { tokenize(vs, buffer); if (vs.size() != 4) return false; x = atof(vs[1].c_str()); y = atof(vs[2].c_str()); z = atof(vs[3].c_str()); } vector3 origin(x, y, z); // now three lines with the x, y, and z axes vector<vector3> axes; for (unsigned int i = 0; i < 3; ++i) { if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "delta", 5)) return false; else { tokenize(vs, buffer); if (vs.size() != 4) return false; x = atof(vs[1].c_str()); y = atof(vs[2].c_str()); z = atof(vs[3].c_str()); axes.push_back(vector3(x, y, z)); } } // Two remaining header lines before the data: /* object 2 class gridconnections counts nx ny nz object 3 class array type double rank 0 times n data follows */ if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "object", 6)) return false; if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "object", 6)) return false; pmol->BeginModify(); pmol->SetDimension(3); OBGridData *gd = new OBGridData; gd->SetAttribute("OpenDX"); // get all values as one vector<double> char *endptr; vector<double> values; int n = voxels[0]*voxels[1]*voxels[2]; int line = 0; values.reserve(n); while (ifs.getline(buffer, BUFF_SIZE)) { ++line; if (EQn(buffer, "attribute", 9)) break; // we're finished with reading data -- although we should probably have a voxel check in here too tokenize(vs, buffer); if (vs.size() == 0) { errorMsg << "Problem reading the OpenDX grid file: cannot" << " read line " << line << ", there does not appear to be any data in it.\n" << buffer << "\n"; obErrorLog.ThrowError(__FUNCTION__, errorMsg.str(), obError); return false; } for (unsigned int l = 0; l < vs.size(); ++l) { values.push_back(strtod(static_cast<const char*>(vs[l].c_str()), &endptr)); } } gd->SetNumberOfPoints(voxels[0], voxels[1], voxels[2]); gd->SetLimits(origin, axes[0], axes[1], axes[2]); gd->SetUnit(OBGridData::ANGSTROM); gd->SetOrigin(fileformatInput); // i.e., is this data from a file or determined by Open Babel gd->SetValues(values); // set the values pmol->SetData(gd); // store the grids in the OBMol pmol->EndModify(); // Trailing control lines /* attribute "dep" string "positions" object "regular positions regular connections" class field component "positions" value 1 component "connections" value 2 component "data" value 3 */ if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "object", 6)) return false; if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "component", 9)) return false; if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "component", 9)) return false; if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "component", 9)) return false; // clean out any remaining blank lines std::streampos ipos; do { ipos = ifs.tellg(); ifs.getline(buffer,BUFF_SIZE); } while(strlen(buffer) == 0 && !ifs.eof() ); ifs.seekg(ipos); return true; }
int main( int argc, char** argv ) { try { std::string origin_string; std::string resolution_string; boost::program_options::options_description description( "options" ); comma::uint32 neighbourhood_radius; description.add_options() ( "help,h", "display help message" ) ( "resolution", boost::program_options::value< std::string >( &resolution_string ), "voxel map resolution, e.g. \"0.2\" or \"0.2,0.2,0.5\"" ) ( "origin", boost::program_options::value< std::string >( &origin_string )->default_value( "0,0,0" ), "voxel map origin" ) ( "neighbourhood-radius,r", boost::program_options::value< comma::uint32 >( &neighbourhood_radius )->default_value( 0 ), "calculate count of neighbours at given radius" ); description.add( comma::csv::program_options::description( "x,y,z,block" ) ); boost::program_options::variables_map vm; boost::program_options::store( boost::program_options::parse_command_line( argc, argv, description), vm ); boost::program_options::notify( vm ); if ( vm.count( "help" ) ) { std::cerr << "downsample a point cloud using a voxel map" << std::endl; std::cerr << std::endl; std::cerr << "usage: cat points.csv | points-to-voxels [options] > voxels.csv" << std::endl; std::cerr << std::endl; std::cerr << "input: points: x,y,z[,block]; default: x,y,z,block" << std::endl; std::cerr << "output: voxels with indices, centroids, and weights (number of points): i,j,k,x,y,z,weight[,neighbour count][,block]" << std::endl; std::cerr << "binary output format: 3ui,3d,ui[,ui][,ui]" << std::endl; std::cerr << std::endl; std::cerr << description << std::endl; std::cerr << std::endl; return 1; } if( vm.count( "resolution" ) == 0 ) { COMMA_THROW( comma::exception, "please specify --resolution" ); } comma::csv::options csv = comma::csv::program_options::get( vm ); Eigen::Vector3d origin; Eigen::Vector3d resolution; comma::csv::ascii< Eigen::Vector3d >().get( origin, origin_string ); if( resolution_string.find_first_of( ',' ) == std::string::npos ) { resolution_string = resolution_string + ',' + resolution_string + ',' + resolution_string; } comma::csv::ascii< Eigen::Vector3d >().get( resolution, resolution_string ); comma::csv::input_stream< input_point > istream( std::cin, csv ); comma::csv::options output_csv = csv; output_csv.full_xpath = true; if( csv.has_field( "block" ) ) // todo: quick and dirty, make output fields configurable? { output_csv.fields = "index,mean,size,block"; if( csv.binary() ) { output_csv.format( "3ui,3d,ui,ui" ); } } else { output_csv.fields = "index,mean,size"; if( csv.binary() ) { output_csv.format( "3ui,3d,ui" ); } } comma::csv::output_stream< centroid > ostream( std::cout, output_csv ); comma::signal_flag is_shutdown; unsigned int block = 0; const input_point* last = NULL; while( !is_shutdown && !std::cin.eof() && std::cin.good() ) { snark::voxel_map< centroid, 3 > voxels( origin, resolution ); if( last ) { voxels.touch_at( last->point )->second += last->point; } while( !is_shutdown && !std::cin.eof() && std::cin.good() ) { last = istream.read(); if( !last || last->block != block ) { break; } voxels.touch_at( last->point )->second += last->point; } if( is_shutdown ) { break; } // for( snark::voxel_map< centroid, 3 >::iterator it = voxels.begin(); it != voxels.end(); ++it ) // { // it->second.block = block; // it->second.index = snark::voxel_map< centroid, 3 >::index_of( it->second.mean, origin, resolution ); // if( neighbourhood_radius > 0 ) // quick and dirty // { // snark::voxel_map< centroid, 3 >::index_type index; // snark::voxel_map< centroid, 3 >::index_type begin = {{ it->first[0] - neighbourhood_radius, it->first[1] - neighbourhood_radius, it->first[2] - neighbourhood_radius }}; // snark::voxel_map< centroid, 3 >::index_type end = {{ it->first[0] + neighbourhood_radius + 1, it->first[1] + neighbourhood_radius + 1, it->first[2] + neighbourhood_radius + 1 }}; // std::size_t size = 0; // Eigen::Vector3d mean( 0, 0, 0 ); // for( index[0] = begin[0]; index[0] < end[0]; ++index[0] ) // { // for( index[1] = begin[1]; index[1] < end[1]; ++index[1] ) // { // for( index[2] = begin[2]; index[2] < end[2]; ++index[2] ) // { // snark::voxel_map< centroid, 3 >::const_iterator nit = voxels.find( index ); // if( nit == voxels.end() ) { continue; } // ostream.write( it->second ); // todo: remove!! // size += nit->second.size; // //mean += ( nit->second.mean * nit->second.size ); // } // } // } // //it->second.size = size; // // //mean /= size; // //it->second.mean = mean; // } // ostream.write( it->second ); // } for( snark::voxel_map< centroid, 3 >::iterator it = voxels.begin(); it != voxels.end(); ++it ) { it->second.block = block; it->second.index = snark::voxel_map< centroid, 3 >::index_of( it->second.mean, origin, resolution ); if( neighbourhood_radius == 0 ) { ostream.write( it->second ); } else { centroid c = it->second; snark::voxel_map< centroid, 3 >::index_type index; snark::voxel_map< centroid, 3 >::index_type begin = {{ it->first[0] - neighbourhood_radius, it->first[1] - neighbourhood_radius, it->first[2] - neighbourhood_radius }}; snark::voxel_map< centroid, 3 >::index_type end = {{ it->first[0] + neighbourhood_radius + 1, it->first[1] + neighbourhood_radius + 1, it->first[2] + neighbourhood_radius + 1 }}; for( index[0] = begin[0]; index[0] < end[0]; ++index[0] ) { for( index[1] = begin[1]; index[1] < end[1]; ++index[1] ) { for( index[2] = begin[2]; index[2] < end[2]; ++index[2] ) { snark::voxel_map< centroid, 3 >::const_iterator nit = voxels.find( index ); if( nit == voxels.end() ) { continue; } c.size += nit->second.size; c.mean += ( nit->second.mean * nit->second.size ); } } } c.mean /= c.size; ostream.write( c ); } } if( !last ) { break; } block = last->block; } if( is_shutdown ) { std::cerr << "points-to-voxels: caught signal" << std::endl; return 1; } return 0; } catch( std::exception& ex ) { std::cerr << argv[0] << ": " << ex.what() << std::endl; } catch( ... ) { std::cerr << argv[0] << ": unknown exception" << std::endl; } return 1; }
Eigen::Matrix3Xd GraspSet::calculateShadow4(const PointList& point_list, double shadow_length) const { double voxel_grid_size = 0.003; // voxel size for points that fill occluded region double num_shadow_points = floor(shadow_length / voxel_grid_size); // number of points along each shadow vector const int num_cams = point_list.getCamSource().rows(); // Calculate the set of cameras which see the points. Eigen::VectorXi camera_set = point_list.getCamSource().rowwise().sum(); // Calculate the center point of the point neighborhood. Eigen::Vector3d center = point_list.getPoints().rowwise().sum(); center /= (double) point_list.size(); // Stores the list of all bins of the voxelized, occluded points. std::vector< Vector3iSet > shadows; shadows.resize(num_cams, Vector3iSet(num_shadow_points * 10000)); for (int i = 0; i < num_cams; i++) { if (camera_set(i) >= 1) { double t0_if = omp_get_wtime(); // Calculate the unit vector that points from the camera position to the center of the point neighborhood. Eigen::Vector3d shadow_vec = center - point_list.getViewPoints().col(i); // Scale that vector by the shadow length. shadow_vec = shadow_length * shadow_vec / shadow_vec.norm(); // Calculate occluded points. // shadows[i] = calculateVoxelizedShadowVectorized4(point_list, shadow_vec, num_shadow_points, voxel_grid_size); calculateVoxelizedShadowVectorized(point_list.getPoints(), shadow_vec, num_shadow_points, voxel_grid_size, shadows[i]); } } // Only one camera view point. if (num_cams == 1) { // Convert voxels back to points. // std::vector<Eigen::Vector3i> voxels(shadows[0].begin(), shadows[0].end()); // Eigen::Matrix3Xd shadow_out = shadowVoxelsToPoints(voxels, voxel_grid_size); // return shadow_out; return shadowVoxelsToPoints(std::vector<Eigen::Vector3i>(shadows[0].begin(), shadows[0].end()), voxel_grid_size); } // Multiple camera view points: find the intersection of all sets of occluded points. double t0_intersection = omp_get_wtime(); Vector3iSet bins_all = shadows[0]; for (int i = 1; i < num_cams; i++) { if (camera_set(i) >= 1) // check that there are points seen by this camera { bins_all = intersection(bins_all, shadows[i]); } } if (MEASURE_TIME) std::cout << "intersection runtime: " << omp_get_wtime() - t0_intersection << "s\n"; // Convert voxels back to points. std::vector<Eigen::Vector3i> voxels(bins_all.begin(), bins_all.end()); Eigen::Matrix3Xd shadow_out = shadowVoxelsToPoints(voxels, voxel_grid_size); return shadow_out; }
arma::cube voxelize(std::vector<CylinderFrustum> cylinders, const Transform &transform, const BoundingBox &boundingBox, int maxExtent) { Length xSide = boundingBox.pMax[0] - boundingBox.pMin[0]; Length ySide = boundingBox.pMax[1] - boundingBox.pMin[1]; Length zSide = boundingBox.pMax[2] - boundingBox.pMin[2]; Length maxLen = max(xSide, max(ySide, zSide)); double xRatio = xSide / maxLen; double yRatio = ySide / maxLen; double zRatio = zSide / maxLen; // x = col, y = row, z = slice arma::cube voxels = arma::zeros(maxExtent * yRatio, maxExtent * xRatio, maxExtent * zRatio); Length3D offset(boundingBox.pMin); for(CylinderFrustum& cylinder : cylinders) { cylinder = CylinderFrustum(cylinder.start - offset, cylinder.end - offset, cylinder.startRadius, cylinder.endRadius); } for(CylinderFrustum& cylinder : cylinders) { cylinder = CylinderFrustum(transform(cylinder.start), transform(cylinder.end), cylinder.startRadius, cylinder.endRadius); } Length step = maxLen / double(maxExtent - 2); Length eps = step; // / 2.0; for(CylinderFrustum& cylinder : cylinders) { BoundingBox localBounds(Point3D(-cylinder.h, -cylinder.startRadius, -cylinder.startRadius), Point3D(cylinder.h, cylinder.startRadius, cylinder.startRadius)); Vector3D perpendicular = cross(Vector3D(1.0, 0.0, 0.0), cylinder.direction); Transform rotation; double sinAngle = perpendicular.length(); if(sinAngle > 0.0) { if(sinAngle > 1.0) { sinAngle -= 2.2204460492503131e-16; // typical machine precision error } double cosAngle = sqrt(1.0 - sinAngle*sinAngle); rotation = rotate(cosAngle, sinAngle, perpendicular); } Transform translation = translate(Length3D(cylinder.center)); BoundingBox bounds = translation(rotation(localBounds)); bounds.expand(eps); int istart = bounds.pMin.x / step; int jstart = bounds.pMin.y / step; int kstart = bounds.pMin.z / step; int iend = bounds.pMax.x / step + 1; int jend = bounds.pMax.y / step + 1; int kend = bounds.pMax.z / step + 1; for(int i = istart; i < iend + 1; i++) { for(int j = jstart; j < jend + 1; j++) { for(int k = kstart; k < kend + 1; k++) { Point3D p(step * (double(i) + 0.5), step * (double(j) + 0.5), step * (double(k) + 0.5)); Length3D diff = p - cylinder.center; Length distance = diff.length(); if(distance > cylinder.h + eps && distance > cylinder.startRadius + eps) { continue; } auto yComponent = dot(diff, cylinder.direction * 1.0_um) / 1.0_um; if(fabs(yComponent) <= cylinder.h + eps) { auto y2 = yComponent*yComponent; auto diff2 = dot(diff, diff); auto distanceToAxis = sqrt(diff2 - y2); double endProportion = (yComponent + cylinder.h) / (2.0 * cylinder.h); Length radius = cylinder.startRadius * (1 - endProportion) + endProportion * cylinder.endRadius; if(distanceToAxis <= radius + eps) { if(voxels.in_range(j, i, k)) { voxels(j, i, k) = 1.0; } } } } } } } return voxels; }
void load_lattice_space(const H5::Group& root, Tspace_* space) { typedef LatticeSpaceHDF5Traits traits_type; uint32_t space_type; // not use double t; double voxel_radius; Real3 edge_lengths; const hsize_t dims[] = {3}; uint32_t is_periodic; #define OPEN_ATTRIBUTE(attribute, type) \ root.openAttribute(#attribute).read(type, &attribute) OPEN_ATTRIBUTE(space_type, H5::PredType::STD_I32LE); OPEN_ATTRIBUTE(t, H5::PredType::IEEE_F64LE); OPEN_ATTRIBUTE(voxel_radius, H5::PredType::IEEE_F64LE); OPEN_ATTRIBUTE(edge_lengths, H5::ArrayType(H5::PredType::NATIVE_DOUBLE, 1, dims)); OPEN_ATTRIBUTE(is_periodic, H5::PredType::STD_I32LE); #undef OPEN_ATTRIBUTE space->set_t(t); space->reset(edge_lengths, voxel_radius, (is_periodic != 0)); std::map<Species, traits_type::h5_species_struct> struct_map; std::map<Species, std::vector<std::pair<ParticleID, Integer> > > voxels_map; std::multimap<std::string, Species> location_map; std::map<Species, std::pair<traits_type::h5_species_struct, std::vector<std::pair<ParticleID, Integer> > > > tmp_map; H5::Group spgroup(root.openGroup("species")); char name_C[32 + 1]; for (hsize_t idx(0); idx < spgroup.getNumObjs(); ++idx) { memset(name_C, 0, 32 + 1); // clear buffer const ssize_t name_len = H5Lget_name_by_idx(spgroup.getLocId(), ".", H5_INDEX_NAME, H5_ITER_INC, idx, name_C, 32, H5P_DEFAULT); H5::Group group(spgroup.openGroup(name_C)); const std::string name_S(name_C); Species species(name_S); // const H5std_string serial = spgroup.getObjnameByIdx(idx); // H5::Group group(spgroup.openGroup(serial.c_str())); // Species species(std::string(serial.c_str())); traits_type::h5_species_struct property; group.openAttribute("property").read( traits_type::get_property_comp(), &property); struct_map.insert(std::make_pair(species, property)); location_map.insert(std::make_pair(property.location, species)); H5::DataSet voxel_dset(group.openDataSet("voxels")); const unsigned int num_voxels( voxel_dset.getSpace().getSimpleExtentNpoints()); boost::scoped_array<traits_type::h5_voxel_struct> h5_voxel_array( new traits_type::h5_voxel_struct[num_voxels]); voxel_dset.read( h5_voxel_array.get(), traits_type::get_voxel_comp()); voxel_dset.close(); group.close(); std::vector<std::pair<ParticleID, Integer> > voxels; for (unsigned int idx(0); idx < num_voxels; ++idx) { voxels.push_back(std::make_pair( ParticleID(std::make_pair(h5_voxel_array[idx].lot, h5_voxel_array[idx].serial)), h5_voxel_array[idx].coordinate)); } voxels_map.insert(std::make_pair(species, voxels)); } spgroup.close(); std::vector<Species> sp_list; traits_type::sort_by_location(location_map, sp_list); for (std::vector<Species>::iterator itr(sp_list.begin()); itr != sp_list.end(); ++itr) { Species species(*itr); traits_type::h5_species_struct property((*struct_map.find(species)).second); std::vector<std::pair<ParticleID, Integer> > voxels((*voxels_map.find(species)).second); if (property.is_structure == 0) space->make_molecular_type(species, property.radius, property.D, property.location); else space->make_structure_type(species, static_cast<Shape::dimension_kind>(property.dimension), property.location); space->add_voxels(species, voxels); } }
// A function for printing the results of the mesh to a file and/or the screen void Vol2mesh :: print_results(double t, bool disable_screen, bool enable_file){ // Convert CGAL object to a vtkUnstructuredGrid // (http://cgal-discuss.949826.n4.nabble.com/mesh-to-vtk-output-td3586974.html) vtkUnstructuredGrid *uGrid; uGrid = CGAL::output_c3t3_to_vtk_unstructured_grid(c3t3_); uGrid->Squeeze(); // Compute mesh quality information vtkMeshQuality *q = vtkMeshQuality::New(); q->SetInput(uGrid); // Variables for storing quality statistics matrix q_mat; vector<string> q_name; // Gather statistics for the mesh get_all_quality_stats(q, q_mat, q_name); // Define variables for building the vector or strings for display int w = 85; // must be greater than 85 char c[w]; vector<string> s; string tmp; // File information header tmp.assign("FILE INFORMATION "); tmp.append(w - tmp.size() - 1, '-'); tmp.append("\n"); s.push_back(tmp); // File input and output names sprintf(c, " %12s: %s\n", "input-file", input_file_.c_str()); s.push_back(c); sprintf(c, " %12s: %s\n\n", "output-file", output_file_.c_str()); s.push_back(c); // Input paramaters header tmp.assign("DEFAULT MESH CRITERIA "); tmp.append(w - tmp.size() - 1, '-'); tmp.append("\n"); s.push_back(tmp); // User suplied options sprintf(c, " %23s: %6.3f\n", "facet-angle", default_criteria_.facet_angle); s.push_back(c); sprintf(c, " %23s: %6.3f\n", "facet-size", default_criteria_.facet_size); s.push_back(c); sprintf(c, " %23s: %6.3f\n", "facet-distance", default_criteria_.facet_distance); s.push_back(c); sprintf(c, " %23s: %6.3f\n", "cell-radius-edge-ratio", default_criteria_.cell_radius_edge_ratio); s.push_back(c); sprintf(c, " %23s: %6.3f\n\n", "cell-size", default_criteria_.cell_size); s.push_back(c); // Mesh results header tmp.assign("MESH RESULTS "); tmp.append(w - tmp.size() - 1, '-'); tmp.append("\n"); s.push_back(tmp); // Mesh results vector<int> pix = pixels(); vector<double> vox = voxels(); sprintf(c, " %23s: %6.3f\n", "execution time (sec.)", t); s.push_back(c); sprintf(c, " %23s: %d, %d, %d\n", "num. of pixels (x,y,z)", pix[0], pix[1], pix[2]); s.push_back(c); sprintf(c, " %23s: %6.3f, %6.3f, %6.3f\n", "pixel dim. (x,y,z)", vox[0], vox[1], vox[2]); s.push_back(c); sprintf(c, " %23s: %6.3f, %6.3f, %6.3f\n", "image dim. (x,y,z)", pix[0]*vox[0], pix[1]*vox[1], pix[2]*vox[2]); s.push_back(c); sprintf(c, " %23s: %d\n", "num. of elements", (int)c3t3_.number_of_cells()); s.push_back(c); sprintf(c, " %23s: %d\n\n", "num. of faces", (int)c3t3_.number_of_facets()); s.push_back(c); // Mesh quality header tmp.assign("TETRAHEDRAL QUALITY "); tmp.append(w - tmp.size() - 1, '-'); tmp.append("\n"); s.push_back(tmp); // Print the mesh quality table labels sprintf(c,"%24s%10s%10s%10s%10s%10s\n", "Name", "Lower", "Upper", "Average", "Std. dev.", "COV (%)"); s.push_back(c); // Print each of the mesh quality results for(int i = 0; i < q_name.size(); ++i){ sprintf(c,"%24s%10.3f%10.3f%10.3f%10.3f%10.3f\n", q_name[i].c_str(), q_mat[i][0], q_mat[i][1], q_mat[i][2], q_mat[i][3], q_mat[i][3] / q_mat[i][2] * 100); s.push_back(c); } // Add sub-domain mesh criteria if(!subdomain_criteria_.empty()){ for(int i = 0; i < subdomain_criteria_.size(); i++){ // Input paramaters header sprintf(c, "SUBDOMAIN %d: MESH CRITERIA ", subdomain_criteria_[i].id); tmp.assign(c); tmp.append(w - tmp.size() - 1, '-'); tmp.append("\n"); s.push_back(tmp); // User suplied options sprintf(c, " %23s: %6.3f\n", "facet-angle", subdomain_criteria_[i].facet_angle); s.push_back(c); sprintf(c, " %23s: %6.3f\n", "facet-size", subdomain_criteria_[i].facet_size); s.push_back(c); sprintf(c, " %23s: %6.3f\n", "facet-distance", subdomain_criteria_[i].facet_distance); s.push_back(c); sprintf(c, " %23s: %6.3f\n", "cell-radius-edge-ratio", subdomain_criteria_[i].cell_radius_edge_ratio); s.push_back(c); sprintf(c, " %23s: %6.3f\n\n", "cell-size", subdomain_criteria_[i].cell_size); s.push_back(c); } } // Output the message to the screen if (!disable_screen){ printf("\n\n"); for (int i = 0; i < s.size(); ++i){ printf("%s", s[i].c_str()); } printf("\n\n"); } // Output the message to a file if (enable_file){ string hdr_file; hdr_file = output_file_ + (string)".info"; FILE* fid = fopen(hdr_file.c_str(), "w"); for (int i = 0; i < s.size(); ++i){ fprintf(fid, "%s", s[i].c_str()); } } }
void ScaleBarObject::draw(float pixelGLRatio, int screenWidth, int screenHeight, int viewWidth, int viewHeight, bool grabsMouse) { VolumeInformation pvlInfo = VolumeInformation::volumeInformation(); QString str; bool horizontal = m_type; float slen = voxels(); if (pvlInfo.voxelUnit > 0) { float avg = (pvlInfo.voxelSize[0] + pvlInfo.voxelSize[1] + pvlInfo.voxelSize[2])/3.0f; str = QString("%1 %2"). \ arg(slen, 0, 'f', Global::floatPrecision()). \ arg(pvlInfo.voxelUnitStringShort()); slen /= avg; } else str = QString("%1 voxels").arg(slen); slen = slen/pixelGLRatio; Vec s0 = Vec(m_pos.x()*viewWidth, m_pos.y()*viewHeight, 1); Vec s1 = s0; if (horizontal) { slen *= (float)viewWidth/(float)screenWidth; s0 -= Vec(slen/2, 0, 0); s1 += Vec(slen/2, 0, 0); } else { slen *= (float)viewHeight/(float)screenHeight; s0 -= Vec(0, slen/2, 0); s1 += Vec(0, slen/2, 0); } glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); // back to front glColor4f(0, 0, 0, 0.8f); if (grabsMouse) { glColor4f(0.5f, 0, 0, 0.8f); glBegin(GL_QUADS); if (horizontal) { glVertex2f(s0.x-5, s0.y-10); glVertex2f(s1.x+5, s0.y-10); glVertex2f(s1.x+5, s0.y+10); glVertex2f(s0.x-5, s0.y+10); } else { glVertex2f(s0.x-10, s0.y-5); glVertex2f(s0.x-10, s1.y+5); glVertex2f(s0.x+10, s1.y+5); glVertex2f(s0.x+10, s0.y-5); } glEnd(); } glDisable(GL_BLEND); glColor3f(1,1,1); glLineWidth(10); glBegin(GL_LINES); glVertex3fv(s0); glVertex3fv(s1); glEnd(); glColor3f(0.5,0.5,0.5); glLineWidth(2); glBegin(GL_LINES); if (horizontal) { glVertex2f(s0.x+slen/2, s0.y-3); glVertex2f(s0.x+slen/2, s1.y+3); } else { glVertex2f(s1.x-3, (s1.y+s0.y)/2); glVertex2f(s0.x+3, (s1.y+s0.y)/2); } glEnd(); glColor3f(0,0,0); glLineWidth(2); glBegin(GL_LINES); if (horizontal) { glVertex2f(s0.x+1, s0.y); glVertex2f(s1.x-1, s1.y); } else { glVertex2f(s0.x, s0.y+1); glVertex2f(s1.x, s1.y-1); } glEnd(); glLineWidth(1); glColor3f(1,1,1); { Vec w0 = Vec(m_pos.x()*screenWidth, (1-m_pos.y())*screenHeight,1); Vec w1 = w0; if (horizontal) { w0 -= Vec(slen/2, 0, 0); w1 += Vec(slen/2, 0, 0); } else { w0 -= Vec(0, slen/2, 0); w1 += Vec(0, slen/2, 0); } QFont tfont = QFont("Helvetica", 12); tfont.setStyleStrategy(QFont::PreferAntialias); QFontMetrics metric(tfont); int mde = metric.descent(); int fht = metric.height()+2; int fwd = metric.width(str)+2; QImage bImage = QImage(fwd, fht, QImage::Format_ARGB32); bImage.fill(0); QPainter bpainter(&bImage); Vec bgcolor = Global::backgroundColor(); bpainter.setBackgroundMode(Qt::OpaqueMode); bpainter.setBackground(QColor(bgcolor.z*255, bgcolor.y*255, bgcolor.x*255)); float bgintensity = (0.3*bgcolor.x + 0.5*bgcolor.y + 0.2*bgcolor.z); QColor penColor(Qt::white); if (bgintensity > 0.5) penColor = Qt::black; bpainter.setPen(penColor); bpainter.setFont(tfont); bpainter.drawText(1, fht-mde, str); QImage cImage = bImage.mirrored(); if (!horizontal) { QMatrix matrix; matrix.rotate(90); cImage = cImage.transformed(matrix); } int x,y; if (horizontal) { x = (w0.x+w1.x)/2 - cImage.width()/2; y = w0.y-3-cImage.height(); if (!m_textpos) y = w0.y+6; } else { x = w1.x+3; if (!m_textpos) x = w1.x-5-cImage.width(); y = (w0.y+w1.y)/2 - cImage.height()/2; } glWindowPos2i(x,y); const uchar *bits = cImage.bits(); glDrawPixels(cImage.width(), cImage.height(), GL_RGBA, GL_UNSIGNED_BYTE, bits); } }