H5::DataSet CompartmentReportHDF5::_createDataset( const uint32_t gid,
                                                   const size_t compCount )
{
    LBASSERT( compCount > 0 );
    LBASSERT( !_reportName.empty( ));

    std::ostringstream neuronName;
    neuronName << "a" << gid;

    H5::Group neuronGroup = _file.createGroup( neuronName.str().c_str( ));
    H5::Group reportGroup = neuronGroup.createGroup( _reportName );

    const int dims = 2;
    const size_t numSteps = (getEndTime() - getStartTime()) / getTimestep();
    const hsize_t mappingDim[dims] = { 1, compCount };
    const hsize_t dataDim[dims] = { numSteps, compCount };
    LBASSERT( numSteps > 0 );

    H5::DataSpace mappingDataspace( dims, mappingDim );
    H5::DataSpace dataDataspace( dims, dataDim );

    H5::DataSet mappingDataset = reportGroup.createDataSet(
             mappingDatasetName, H5::PredType::NATIVE_FLOAT, mappingDataspace );
    H5::DataSet dataDataset = reportGroup.createDataSet( dataDatasetName,
                                    H5::PredType::NATIVE_FLOAT, dataDataspace );

    _datas[gid] = dataDataset;

    _createMappingAttributes( mappingDataset );
    _createDataAttributes( dataDataset );

    return mappingDataset;
}
Beispiel #2
0
/*********************************************************
FunctionName:RecursiveWriteData
FunctionDesc:递归创建Group
InputParam:
OutputParam:
Return:
Author:xiaowei.han
*********************************************************/
void RecursiveWriteData(H5::Group& NodeGroup, Hdf5_Wrapper::LP_HDF5_DATA pData)
{
	using namespace H5;
	//参数合法性判断
	if (nullptr == pData)
	{
		return;
	}



	//如果不带子节点
	if (pData->SubDataArray.empty())
	{
		//判断数据类型
		boost::scoped_ptr<CAbstractDataTypeHandler> pHandlder(CDataTypeHandlerFactory::CreateDataTypeHandler(pData->Header.eumDataType, pData->Header.nDataByte));
		if (pHandlder)
		{
			pHandlder->WriteDataSet(NodeGroup, pData);
		}
	}
	//如果有子节点
	else
	{
		//创建一个Group
		std::string strGroupKeyName = Utility::GB2312ToUTF8(pData->strKeyName);
		auto ChildGroupNode = NodeGroup.createGroup(strGroupKeyName);

		//插入属性
		for (auto& AttributeElement : pData->AttributeArray)
		{
			boost::scoped_ptr<CAbstractAttrHanlder> p(CreateAttrHandler(AttributeElement.Header.eumDataType, AttributeElement.Header.nDataByte));
			if (p)
			{
				p->WriteAttr(ChildGroupNode, AttributeElement);
			}
		}

		for (auto& SubGroupElement : pData->SubDataArray)
		{
			RecursiveWriteData(ChildGroupNode, SubGroupElement);
		}
	}
}
Beispiel #3
0
void Bundle2::streamPOI(size_t frame) {
	H5::DataSpace scalar;
	H5::Group poiGroup = streamFile_->openGroup("/POI");
	for(size_t i = poiFirstFrame_; i <= frame; ++i) {
		const std::string frameGroupName = boost::str(boost::format("Frame %1$04d") % i);
		H5::Group frameGroup = poiGroup.createGroup(frameGroupName);

		hsize_t count = poi_[(ptrdiff_t)i - (ptrdiff_t)poiFirstFrame_].size();
		H5::Attribute attr = frameGroup.createAttribute("count", H5::PredType::STD_U64LE, scalar);
		attr.write(H5::PredType::NATIVE_HSIZE, &count);
		attr.close();

		for(size_t camera = 0; camera < poi_[(ptrdiff_t)i - (ptrdiff_t)poiFirstFrame_].size(); ++camera)
			poi_[(ptrdiff_t)i - (ptrdiff_t)poiFirstFrame_][camera].save(frameGroup, camera);

		frameGroup.close();
	}
	poiGroup.close();
	scalar.close();

	poi_.erase(poi_.begin(), poi_.begin() + (ptrdiff_t)frame - (ptrdiff_t)poiFirstFrame_ + 1);
	poiFirstFrame_ = frame + 1;
}
inline
void vtkStandardMeshRepresenter::Save(const H5::Group& fg) const {
	using namespace H5;

	statismo::MatrixType vertexMat = statismo::MatrixType::Zero(3,
			m_reference->GetNumberOfPoints());

	for (unsigned i = 0; i < m_reference->GetNumberOfPoints(); i++) {
		PointType pt = m_reference->GetPoint(i);
		for (unsigned d = 0; d < 3; d++) {
			vertexMat(d, i) = pt[d];
		}
	}
	HDF5Utils::writeMatrix(fg, "./points", vertexMat);

	// check the dimensionality of a face (i.e. the number of points it has). We assume that
	// all the cells are the same.
	unsigned numPointsPerCell = 0;
	if (m_reference->GetNumberOfCells() > 0) {
		numPointsPerCell = m_reference->GetCell(0)->GetNumberOfPoints();
	}

	typedef statismo::GenericEigenType<unsigned int>::MatrixType UIntMatrixType;
	UIntMatrixType facesMat = UIntMatrixType::Zero(numPointsPerCell,
			m_reference->GetNumberOfCells());

	for (unsigned i = 0; i < m_reference->GetNumberOfCells(); i++) {
		vtkCell* cell = m_reference->GetCell(i);
		assert(numPointsPerCell == cell->GetNumberOfPoints());
		for (unsigned d = 0; d < numPointsPerCell; d++) {
			facesMat(d, i) = cell->GetPointIds()->GetId(d);
		}
	}

	HDF5Utils::writeMatrixOfType<unsigned int>(fg, "./cells", facesMat);

	H5::Group pdGroup = fg.createGroup("pointData");

	vtkPointData* pd = m_reference->GetPointData();
	if (pd != 0 && pd->GetScalars() != 0) {
		vtkDataArray* scalars = pd->GetScalars();
		WriteDataArray(pdGroup, "scalars", scalars);
	}
	if (pd != 0 && pd->GetVectors() != 0) {
		vtkDataArray* vectors = pd->GetVectors();
		WriteDataArray(pdGroup, "vectors", vectors);
	}
	if (pd != 0 && pd->GetNormals() != 0) {
		vtkDataArray* normals = pd->GetNormals();
		WriteDataArray(pdGroup, "normals", normals);
	}

	H5::Group cdGroup = fg.createGroup("cellData");
	vtkCellData* cd = m_reference->GetCellData();
	if (cd != 0 && cd->GetScalars() != 0) {
		vtkDataArray* scalars = cd->GetScalars();
		WriteDataArray(cdGroup, "scalars", scalars);
	}
	if (cd != 0 && cd->GetVectors() != 0) {
		vtkDataArray* vectors = cd->GetVectors();
		WriteDataArray(cdGroup, "vectors", vectors);
	}
	if (cd != 0 && cd->GetNormals() != 0) {
		vtkDataArray* normals = cd->GetNormals();
		WriteDataArray(cdGroup, "normals", normals);
	}

}
Beispiel #5
0
 /** 
  * \brief Create a subgroup.
  * \param key : the name of the subgroup
  * \param delete_if_exists : unlink the group if it exists 
  */
 group create_group(std::string const & key, bool delete_if_exists = true) const {
  unlink_key_if_exists(key); 
  return _g.createGroup(key.c_str());
 }
Beispiel #6
0
// Bundle management
void Bundle2::save(const boost::filesystem::path& fileName) const {
	// Creating HDF5 file
	H5::H5File bundleFile(fileName.string(), H5F_ACC_TRUNC);
	storeParameters(bundleFile);

	H5::DataSpace scalar;

	// Saving POI
	H5::Group poiGroup = bundleFile.createGroup("/POI");

	H5::Attribute attr = poiGroup.createAttribute("count", H5::PredType::STD_U64LE, scalar);
	hsize_t count = poi_.size();
	attr.write(H5::PredType::NATIVE_HSIZE, &count);
	attr.close();

	for(size_t frame = 0; frame < poi_.size(); ++frame) {
		const std::string frameGroupName = boost::str(boost::format("Frame %1$04d") % frame);
		H5::Group frameGroup = poiGroup.createGroup(frameGroupName);

		count = poi_[frame].size();
		attr = frameGroup.createAttribute("count", H5::PredType::STD_U64LE, scalar);
		attr.write(H5::PredType::NATIVE_HSIZE, &count);
		attr.close();

		for(size_t camera = 0; camera < poi_[frame].size(); ++camera)
			poi_[frame][camera].save(frameGroup, camera);

		frameGroup.close();
	}

	poiGroup.close();

	// Saving key frames
	H5::Group bundleGroup = bundleFile.createGroup("/Bundle");

	H5::Group framesGroup = bundleGroup.createGroup("Frames");

	count = frames_.size();
	attr = framesGroup.createAttribute("count", H5::PredType::STD_U64LE, scalar);
	attr.write(H5::PredType::NATIVE_HSIZE, &count);
	attr.close();

	for(deque<Frame*>::const_iterator it = frames_.begin(); it != frames_.end(); it++) {
		(*it)->save(framesGroup);
	}

	framesGroup.close();

	// Saving tracks
	const hsize_t chunkDim[] = { 2, 1 };
	H5::DSetCreatPropList propList;
	propList.setLayout(H5D_CHUNKED);
	propList.setChunk(2, chunkDim);
	propList.setDeflate(9);

	H5::VarLenType tracksDatasetType(&H5::PredType::STD_U64LE);

	hsize_t tracksDim[] = { tracks_.size(), 2 };
    hsize_t tracksMaxDim[] = { H5S_UNLIMITED, 2 };
	H5::DataSpace tracksDataspace(2, tracksDim, tracksMaxDim);

	H5::DataSet tracksDataset = bundleGroup.createDataSet("Tracks", tracksDatasetType, tracksDataspace, propList);

	for(size_t i = 0; i < tracks_.size(); ++i)
		tracks_[i]->save(tracksDataset, i);

	tracksDataset.close();
	tracksDataspace.close();
	tracksDatasetType.close();
	propList.close();

	bundleGroup.close();

	scalar.close();
	bundleFile.close();
}
Beispiel #7
0
void Bundle2::initFrameStream_() {
	H5::DataSpace scalar;

	// Creating datasets for each frame
	H5::Group bundleGroup = streamFile_->createGroup("/Bundle");
	H5::Group framesGroup = bundleGroup.createGroup("Frames");

	hsize_t count = frames_.size();
	H5::Attribute attr = framesGroup.createAttribute("count", H5::PredType::STD_U64LE, scalar);
	attr.write(H5::PredType::NATIVE_HSIZE, &count);
	attr.close();

	// Defining frame dataset property
	hsize_t chunkDim[] = { 1, 2, 10 };
	H5::DSetCreatPropList propList;
	propList.setLayout(H5D_CHUNKED);
	propList.setChunk(3, chunkDim);
	propList.setDeflate(9);

	// Definig dataset dataspace
	hsize_t max_dim[] = { numCameras_, 2, H5S_UNLIMITED };
	hsize_t dim[] = { numCameras_, 2, 0 };
	H5::DataSpace ds(3, dim, max_dim);

	for(deque<Frame*>::const_iterator it = frames_.begin(); it != frames_.end(); it++) {
		const std::string datasetName = boost::str(boost::format("Frame %1$04d") % (*it)->number());

		// Creating dataset
		H5::DataSet frameData = framesGroup.createDataSet(datasetName, H5::PredType::IEEE_F32LE, ds, propList);

		// Writing global number
		attr = frameData.createAttribute("globalNumber", H5::PredType::STD_U64LE, scalar);
		count = (*it)->globalNumber();
		attr.write(H5::PredType::NATIVE_HSIZE, &count);
		attr.close();

		// Clean up!
		frameData.close();
	}

	// Clean up!
	ds.close();
	propList.close();

	// Creating tracks dataset
	hsize_t chunkDim2[] = { 2, 10 };
	propList = H5::DSetCreatPropList();
	propList.setLayout(H5D_CHUNKED);
	propList.setChunk(2, chunkDim);
	propList.setDeflate(9);

	H5::VarLenType tracksDatasetType(&H5::PredType::STD_U64LE);

	hsize_t tracksDim[] = { 0, 2 };
	hsize_t tracksMaxDim[] = { H5S_UNLIMITED, 2 };
	H5::DataSpace tracksDataspace(2, tracksDim, tracksMaxDim);

	H5::DataSet tracksDataset = bundleGroup.createDataSet("Tracks", tracksDatasetType, tracksDataspace, propList);

	tracksDataset.close();
	tracksDataspace.close();
	tracksDatasetType.close();
	propList.close();

	framesGroup.close();
	bundleGroup.close();
	scalar.close();
}
Beispiel #8
0
void Bundle2::saveGeometry(const boost::filesystem::path& fileName) const {
	H5::H5File bundleFile;
	bundleFile.openFile(fileName.string(), H5F_ACC_RDWR);

	H5::Group rootGroup = bundleFile.openGroup("/");

	// If the group "Geometry" exists, delete it!
	if(checkGeometry_(bundleFile)) {
		rootGroup.unlink("Geometry");
	}

	// Creating group Geometry
	H5::Group geometryGroup = rootGroup.createGroup("Geometry");

	// Saving poses
	const hsize_t posesChunkDim[] = { 3, 12 };
	H5::DSetCreatPropList posesPropList;
	posesPropList.setLayout(H5D_CHUNKED);
	posesPropList.setChunk(2, posesChunkDim);
	posesPropList.setDeflate(9);

	const hsize_t posesMaxDim[] = { H5S_UNLIMITED, 12 };
	const hsize_t posesCurDim[] = { frames_.size(), 12 };
	H5::DataSpace posesDS(2, posesCurDim, posesMaxDim);

	H5::DataSet posesDataSet = geometryGroup.createDataSet("Poses", H5::PredType::IEEE_F64LE, posesDS, posesPropList);

	double* posesData = (double*)malloc(frames_.size()*12*sizeof(double));
	size_t i = 0;
	for(deque<Frame*>::const_iterator it = frames_.begin(); it != frames_.end(); it++) {
		posesData[i*12] = (*it)->pose()->t().x();
		posesData[i*12 + 1] = (*it)->pose()->t().y();
		posesData[i*12 + 2] = (*it)->pose()->t().z();

		core::Matrix<double> R = (*it)->pose()->R();
		posesData[i*12 + 3] = R[0][0];
		posesData[i*12 + 4] = R[1][0];
		posesData[i*12 + 5] = R[2][0];
		posesData[i*12 + 6] = R[0][1];
		posesData[i*12 + 7] = R[1][1];
		posesData[i*12 + 8] = R[2][1];
		posesData[i*12 + 9] = R[0][2];
		posesData[i*12 + 10] = R[1][2];
		posesData[i*12 + 11] = R[2][2];

		++i;
	}

	posesDataSet.write((const void*)posesData, H5::PredType::NATIVE_DOUBLE, H5::DataSpace::ALL, H5::DataSpace::ALL);
	free((void*)posesData);
	posesDataSet.close();
	posesDS.close();

	// Saving points
	const hsize_t pointsChunkDim[] = {10, 3};
	H5::DSetCreatPropList pointsPropList;
	pointsPropList.setLayout(H5D_CHUNKED);
	pointsPropList.setChunk(2, pointsChunkDim);
	pointsPropList.setDeflate(9);

	const hsize_t pointsMaxDim[] = { H5S_UNLIMITED, 3 };
	const hsize_t pointsCurDim[] = { tracks_.size(), 3 };
	H5::DataSpace pointsDS(2, pointsCurDim, pointsMaxDim);

	H5::DataSet pointsDataSet = geometryGroup.createDataSet("Points", H5::PredType::IEEE_F64LE, pointsDS, pointsPropList);

	double* pointsData = (double*)malloc(tracks_.size()*3*sizeof(double));

	i = 0;
	for(deque<Track*>::const_iterator it = tracks_.begin(); it != tracks_.end(); it++) {
		pointsData[i*3] = (*it)->point()->coords().x();
		pointsData[i*3 + 1] = (*it)->point()->coords().y();
		pointsData[i*3 + 2] = (*it)->point()->coords().z();

		++i;
	}

	pointsDataSet.write((const void*)pointsData, H5::PredType::NATIVE_DOUBLE, H5::DataSpace::ALL, H5::DataSpace::ALL);
	free((void*)pointsData);
	pointsDataSet.close();
	pointsDS.close();

	// Saving inlier information
	const hsize_t inliersChunkDim[] = { 3 };
	H5::DSetCreatPropList inliersPropList;
	inliersPropList.setLayout(H5D_CHUNKED);
	inliersPropList.setChunk(1, inliersChunkDim);
	inliersPropList.setDeflate(9);

	const hsize_t inliersMaxDim[] = { H5S_UNLIMITED };
	const hsize_t inliersCurDim[] = { frames_.size() };
	H5::DataSpace inliersDS(1, inliersCurDim, inliersMaxDim);

	H5::VarLenType inliersType(&H5::PredType::STD_U8LE);

	H5::DataSet inliersDataSet = geometryGroup.createDataSet("Inliers", inliersType, inliersDS, inliersPropList);

	i = 0;
	for(deque<Frame*>::const_iterator it = frames_.begin(); it != frames_.end(); it++) {
		hvl_t inliersLine;

        size_t inliersLineSize = 0;
        for(size_t j = 0; j < (*it)->size(); ++j) {
            View& v = (**it)[j];
            for(unsigned int cam = 0; cam < v.numCameras(); ++cam) {
                if(v.inCamera(cam)) ++inliersLineSize;
            }
        }

		inliersLine.len = inliersLineSize;
		inliersLine.p = malloc(inliersLineSize*sizeof(unsigned char));

        size_t k = 0;
		for(size_t j = 0; j < (*it)->size(); ++j) {
            View& v = (**it)[j];
            for(unsigned int cam = 0; cam < v.numCameras(); ++cam) {
                if(v.inCamera(cam)) {
                    ((unsigned char*)(inliersLine.p))[k] = v.ray(cam).inlier()?1:0;
                    ++k;
                }
            }
        }

		const hsize_t dsOffset[] = { i };
		const hsize_t dsCount[] = { 1 };
		H5::DataSpace inliersCurDS = inliersDataSet.getSpace();
		inliersCurDS.selectHyperslab(H5S_SELECT_SET, dsCount, dsOffset);

		const hsize_t memDim[] = { 1 };
		H5::DataSpace memDS(1, memDim, memDim);

		H5::VarLenType memType(&H5::PredType::NATIVE_UCHAR);

		inliersDataSet.write((const void*)&inliersLine, memType, memDS, inliersCurDS);

		memType.close();
		memDS.close();
		inliersCurDS.close();

		free(inliersLine.p);

		++i;
	}

	inliersDataSet.close();
	inliersType.close();
	inliersDS.close();

	// Saving curves
	if(!curves_.empty()) {
		const hsize_t chunkDim[] = { 5 };
		H5::DSetCreatPropList propList;
		propList.setLayout(H5D_CHUNKED);
		propList.setChunk(1, chunkDim);
		propList.setDeflate(9);

		H5::VarLenType curveDatasetType(&H5::PredType::STD_U64LE);

		hsize_t curvesDim[] = { curves_.size() };
		hsize_t curvesMaxDim[] = { H5S_UNLIMITED };
		H5::DataSpace curvesDataspace(1, curvesDim, curvesMaxDim);

		H5::DataSet curvesDataset = geometryGroup.createDataSet("Curves", curveDatasetType, curvesDataspace, propList);

		for(size_t i = 0; i < curves_.size(); ++i) {
			hvl_t curveLine;

			curveLine.len = curves_[i].size();
			curveLine.p = malloc(curves_[i].size()*sizeof(size_t));

			for(size_t j = 0; j < curves_[i].size(); ++j) ((size_t*)(curveLine.p))[j] = curves_[i].track(j);

			const hsize_t dsOffset[] = { i };
			const hsize_t dsCount[] = { 1 };
			H5::DataSpace curDS = curvesDataset.getSpace();
			curDS.selectHyperslab(H5S_SELECT_SET, dsCount, dsOffset);

			const hsize_t memDim[] = { 1 };
			H5::DataSpace memDS(1, memDim, memDim);

			H5::VarLenType memType(&H5::PredType::NATIVE_HSIZE);

			curvesDataset.write((const void*)&curveLine, memType, memDS, curDS);

			memType.close();
			memDS.close();
			curDS.close();

			free(curveLine.p);
 		}

		curvesDataset.close();
		curvesDataspace.close();
		curveDatasetType.close();
		propList.close();
	}

	geometryGroup.close();
	rootGroup.close();
	bundleFile.close();
}