Esempio n. 1
0
    void DCDataSet::append(size_t count, size_t offset, size_t stride, const void* data)
    throw (DCException)
    {
        log_msg(2, "DCDataSet::append");

        if (!opened)
            throw DCException(getExceptionString("append: Dataset has not been opened/created."));

        log_msg(3, "logical_size = %s", getLogicalSize().toString().c_str());

        Dimensions target_offset(getLogicalSize());
        // extend size (dataspace) of existing dataset with count elements
        getLogicalSize()[0] += count;

        hsize_t * max_dims = new hsize_t[ndims];
        for (size_t i = 0; i < ndims; ++i)
            max_dims[i] = H5F_UNLIMITED;

        if (H5Sset_extent_simple(dataspace, 1, getLogicalSize().getPointer(), max_dims) < 0)
            throw DCException(getExceptionString("append: Failed to set new extent"));

        delete[] max_dims;
        max_dims = NULL;

        log_msg(3, "logical_size = %s", getLogicalSize().toString().c_str());

        if (H5Dset_extent(dataset, getLogicalSize().getPointer()) < 0)
            throw DCException(getExceptionString("append: Failed to extend dataset"));

        // select the region in the target DataSpace to write to
        Dimensions dim_data(count, 1, 1);
        if (H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, target_offset.getPointer(),
                NULL, dim_data.getPointer(), NULL) < 0 ||
                H5Sselect_valid(dataspace) < 0)
            throw DCException(getExceptionString("append: Invalid target hyperslap selection"));

        // append data to the dataset.
        // select the region in the source DataSpace to read from
        Dimensions dim_src(offset + count * stride, 1, 1);
        hid_t dsp_src = H5Screate_simple(1, dim_src.getPointer(), NULL);
        if (dsp_src < 0)
            throw DCException(getExceptionString("append: Failed to create src dataspace while appending"));

        if (H5Sselect_hyperslab(dsp_src, H5S_SELECT_SET, Dimensions(offset, 0, 0).getPointer(),
                Dimensions(stride, 1, 1).getPointer(), dim_data.getPointer(), NULL) < 0 ||
                H5Sselect_valid(dsp_src) < 0)
            throw DCException(getExceptionString("append: Invalid source hyperslap selection"));

        if (!data || (count == 0))
        {
            H5Sselect_none(dataspace);
            data = NULL;
        }

        if (H5Dwrite(dataset, this->datatype, dsp_src, dataspace, dsetWriteProperties, data) < 0)
            throw DCException(getExceptionString("append: Failed to append dataset"));

        H5Sclose(dsp_src);
    }
		//
		//  Feature
		//
		// Given the source and target, find and place feature patches on the given output
		void placeFeaturePatches(const Heightmap *source, const Heightmap *target, Heightmap *output, int patch_size) {
			
			// perform ppa on both inputs
			ppa::RidgeGraph source_ridges = ppa::ppa_Tasse(source);
			ppa::RidgeGraph target_ridges = ppa::ppa_Tasse(target);

			// find source (candidate) and target (placement) points
			vector<ppa::vertex> source_points = getSpacedVerticies(source_ridges, patch_size/2);
			vector<ppa::vertex> target_points = getSpacedVerticies(target_ridges, patch_size/2);

			// create a list of all candidates
			vector<Patch> candidates;
			for (ppa::vertex v : source_points) {
				candidates.emplace_back(source_ridges, v.id, patch_size);
			}

			// flip
			size_t patch_count = candidates.size();
			for (size_t i = 0; i < patch_count; i++) {
				candidates.push_back(candidates[i].flipHorz());
			}

			// rotate
			patch_count = candidates.size();
			for (size_t i = 0; i < patch_count; i++) {
				for (float rot = cgra::pi / 4; rot < cgra::pi * 2; rot += cgra::pi / 4) {
					candidates.push_back(candidates[i].rotate(rot));
				}
			}

			// TODO flip
			// TODO rotate
			// ALL patches


			// for each target (placement) point
			for (ppa::vertex v : target_points) {
				

				// Get Target Patch
				ivec2 target_offset(v.p - patch_size / 2); // top left of the patch
				Patch target_patch(target_ridges, v.id, patch_size);

				Heightmap best_patch = bestPatch(output, target_patch, target_offset, candidates);
				
				mergePatch(output, &best_patch, target_offset);
			}
		}
		//
		//  NON-Feature
		//
		void placeNonFeaturePatches(const Heightmap *source, const Heightmap *target, Heightmap *output, int patch_size) {

			ppa::RidgeGraph source_ridges = ppa::ppa_Tasse(source);
			vector<ppa::vertex> source_points = getSpacedVerticies(source_ridges, patch_size / 2);





			Array<bool> feature_mask(source->size(), false);
			Array<bool> feature_patch(patch_size *1, patch_size * 1, true);

			// Blot out feature mask (with a buffer)
			for (ppa::vertex v : source_points) {
				feature_mask.block(feature_patch, v.p - (patch_size));
			}


			// create a list of all candidates (non-feature patches)
			// Iterate over feature mask
			vector<Patch> candidates;
			for (int y = patch_size/2; y < source->height() - patch_size/2; ++y) {
				for (int x = patch_size/2; x < source->width() - patch_size/2; ++x) {
					ivec2 p(x, y);

					// If this position is not a feature
					if (!feature_mask.at(p)) {
						// Add to candidates
						candidates.emplace_back(Patch(*source, ivec2(p - patch_size / 2), patch_size));
						feature_mask.block(feature_patch, p - (patch_size / 2));
					}

					//if (candidates.size() > 100) break;
				}
				//if (candidates.size() > 100) break;
			}

			// TODO flip
			// TODO rotate
			// ALL patches
	
			// for every point that does not have a value
			for (int y = 0; y < output->height(); ++y) {
				for (int x = 0; x < output->width(); ++x) {
					if (!output->isnan(x, y)) continue;
					ivec2 p(x, y);


					static int asd = 0;
					//if (++asd>100) return; // stop after x amount;

					// // Get Target Patch
					ivec2 target_offset(p - patch_size / 2);
					Patch target_patch(*output, target_offset, patch_size);

					Heightmap best_patch = bestPatch(output, target_patch, target_offset, candidates);

					mergePatch(output, &best_patch, target_offset);
				}
			}
		}
Esempio n. 4
0
//-----------------------------------------------------------------------------
// render()
//-----------------------------------------------------------------------------
BOOL LLVisualParamHint::render()
{
	LLVisualParamReset::sDirty = TRUE;
	LLVOAvatar* avatarp = gAgent.getAvatarObject();

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glOrtho(0.0f, mWidth, 0.0f, mHeight, -1.0f, 1.0f);

	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();

	LLGLSUIDefault gls_ui;
	//LLGLState::verify(TRUE);
	mBackgroundp->draw(0, 0, mWidth, mHeight);

	glMatrixMode(GL_PROJECTION);
	glPopMatrix();

	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();

	mNeedsUpdate = FALSE;
	mIsVisible = TRUE;

	LLViewerJointMesh* cam_target_joint = NULL;
	const std::string& cam_target_mesh_name = mVisualParam->getCameraTargetName();
	if( !cam_target_mesh_name.empty() )
	{
		cam_target_joint = (LLViewerJointMesh*)avatarp->getJoint( cam_target_mesh_name );
	}
	if( !cam_target_joint )
	{
		cam_target_joint = (LLViewerJointMesh*)gMorphView->getCameraTargetJoint();
	}
	if( !cam_target_joint )
	{
		cam_target_joint = (LLViewerJointMesh*)avatarp->getJoint("mHead");
	}

	LLQuaternion avatar_rotation;
	LLJoint* root_joint = avatarp->getRootJoint();
	if( root_joint )
	{
		avatar_rotation = root_joint->getWorldRotation();
	}

	LLVector3 target_joint_pos = cam_target_joint->getWorldPosition();

	LLVector3 target_offset( 0, 0, mVisualParam->getCameraElevation() );
	LLVector3 target_pos = target_joint_pos + (target_offset * avatar_rotation);

	F32 cam_angle_radians = mVisualParam->getCameraAngle() * DEG_TO_RAD;
	LLVector3 camera_snapshot_offset( 
		mVisualParam->getCameraDistance() * cosf( cam_angle_radians ),
		mVisualParam->getCameraDistance() * sinf( cam_angle_radians ),
		mVisualParam->getCameraElevation() );
	LLVector3 camera_pos = target_joint_pos + (camera_snapshot_offset * avatar_rotation);
	
	gGL.flush();
	
	LLViewerCamera::getInstance()->setAspect((F32)mWidth / (F32)mHeight);
	LLViewerCamera::getInstance()->setOriginAndLookAt(
		camera_pos,		// camera
		LLVector3(0.f, 0.f, 1.f),						// up
		target_pos );	// point of interest

	LLViewerCamera::getInstance()->setPerspective(FALSE, mOrigin.mX, mOrigin.mY, mWidth, mHeight, FALSE);

	if (avatarp->mDrawable.notNull())
	{
		LLDrawPoolAvatar *avatarPoolp = (LLDrawPoolAvatar *)avatarp->mDrawable->getFace(0)->getPool();
		LLGLDepthTest gls_depth(GL_TRUE, GL_TRUE);
		gGL.setAlphaRejectSettings(LLRender::CF_ALWAYS);
		gGL.setSceneBlendType(LLRender::BT_REPLACE);
		avatarPoolp->renderAvatars(avatarp);  // renders only one avatar
		gGL.setSceneBlendType(LLRender::BT_ALPHA);
		gGL.setAlphaRejectSettings(LLRender::CF_DEFAULT);
	}
	avatarp->setVisualParamWeight(mVisualParam, mLastParamWeight);
	gGL.color4f(1,1,1,1);
	mTexture->setGLTextureCreated(true);
	return TRUE;
}
Esempio n. 5
0
//-----------------------------------------------------------------------------
// render()
//-----------------------------------------------------------------------------
BOOL LLVisualParamHint::render()
{
	LLVisualParamReset::sDirty = TRUE;

	gGL.pushUIMatrix();
	gGL.loadUIIdentity();

	gGL.matrixMode(LLRender::MM_PROJECTION);
	gGL.pushMatrix();
	gGL.loadIdentity();
	gGL.ortho(0.0f, mFullWidth, 0.0f, mFullHeight, -1.0f, 1.0f);

	gGL.matrixMode(LLRender::MM_MODELVIEW);
	gGL.pushMatrix();
	gGL.loadIdentity();

	if (LLGLSLShader::sNoFixedFunction)
	{
		gUIProgram.bind();
	}

	LLGLSUIDefault gls_ui;
	//LLGLState::verify(TRUE);
	mBackgroundp->draw(0, 0, mFullWidth, mFullHeight);

	gGL.matrixMode(LLRender::MM_PROJECTION);
	gGL.popMatrix();

	gGL.matrixMode(LLRender::MM_MODELVIEW);
	gGL.popMatrix();

	mNeedsUpdate = FALSE;
	mIsVisible = TRUE;

	LLQuaternion avatar_rotation;
	LLJoint* root_joint = gAgentAvatarp->getRootJoint();
	if( root_joint )
	{
		avatar_rotation = root_joint->getWorldRotation();
	}

	LLVector3 target_joint_pos = mCamTargetJoint->getWorldPosition();

	LLVector3 target_offset( 0, 0, mVisualParam->getCameraElevation() );
	LLVector3 target_pos = target_joint_pos + (target_offset * avatar_rotation);

	F32 cam_angle_radians = mVisualParam->getCameraAngle() * DEG_TO_RAD;
	LLVector3 camera_snapshot_offset( 
		mVisualParam->getCameraDistance() * cosf( cam_angle_radians ),
		mVisualParam->getCameraDistance() * sinf( cam_angle_radians ),
		mVisualParam->getCameraElevation() );
	LLVector3 camera_pos = target_joint_pos + (camera_snapshot_offset * avatar_rotation);
	
	gGL.flush();
	
	LLViewerCamera::getInstance()->setAspect((F32)mFullWidth / (F32)mFullHeight);
	LLViewerCamera::getInstance()->setOriginAndLookAt(
		camera_pos,			// camera
		LLVector3::z_axis,	// up
		target_pos );		// point of interest

	LLViewerCamera::getInstance()->setPerspective(FALSE, mOrigin.mX, mOrigin.mY, mFullWidth, mFullHeight, FALSE);

	if (gAgentAvatarp->mDrawable.notNull() &&
		gAgentAvatarp->mDrawable->getFace(0))
	{
		LLDrawPoolAvatar *avatarPoolp = (LLDrawPoolAvatar *)gAgentAvatarp->mDrawable->getFace(0)->getPool();
		LLGLDepthTest gls_depth(GL_TRUE, GL_TRUE);
		gGL.setAlphaRejectSettings(LLRender::CF_ALWAYS);
		gGL.setSceneBlendType(LLRender::BT_REPLACE);
		avatarPoolp->renderAvatars(gAgentAvatarp);  // renders only one avatar
		gGL.setSceneBlendType(LLRender::BT_ALPHA);
		gGL.setAlphaRejectSettings(LLRender::CF_DEFAULT);
	}
	gAgentAvatarp->setVisualParamWeight(mVisualParam->getID(), mLastParamWeight);
	mWearablePtr->setVisualParamWeight(mVisualParam->getID(), mLastParamWeight, FALSE);
	gAgentAvatarp->updateVisualParams();
	gGL.color4f(1,1,1,1);
	mGLTexturep->setGLTextureCreated(true);
	gGL.popUIMatrix();

	return TRUE;
}