示例#1
0
void DiagSplit::split_quad(Patch *patch)
{
	QuadDice::SubPatch sub_split;
	QuadDice::EdgeFactors ef_split;

	sub_split.patch = patch;
	sub_split.P00 = make_float2(0.0f, 0.0f);
	sub_split.P10 = make_float2(1.0f, 0.0f);
	sub_split.P01 = make_float2(0.0f, 1.0f);
	sub_split.P11 = make_float2(1.0f, 1.0f);

	ef_split.tu0 = T(patch, sub_split.P00, sub_split.P10);
	ef_split.tu1 = T(patch, sub_split.P01, sub_split.P11);
	ef_split.tv0 = T(patch, sub_split.P00, sub_split.P01);
	ef_split.tv1 = T(patch, sub_split.P10, sub_split.P11);

	split(sub_split, ef_split);

	QuadDice dice(params);

	for(size_t i = 0; i < subpatches_quad.size(); i++) {
		QuadDice::SubPatch& sub = subpatches_quad[i];
		QuadDice::EdgeFactors& ef = edgefactors_quad[i];

		ef.tu0 = max(ef.tu0, 1);
		ef.tu1 = max(ef.tu1, 1);
		ef.tv0 = max(ef.tv0, 1);
		ef.tv1 = max(ef.tv1, 1);

		dice.dice(sub, ef);
	}

	subpatches_quad.clear();
	edgefactors_quad.clear();
}
示例#2
0
    std::vector<float3> oabf_line( int ix, int iy, const cpu_image& lfm_, float sigma_d_,
                                   float sigma_r_, bool tangential_, float precision_ )
    {
        std::deque<float3> L;

        float4 l = lfm_.at<float4>(ix, iy);
        float2 t;
        float sigma_d = sigma_d_;
        if (tangential_) {
            t = make_float2(l.x, l.y);
            sigma_d *= l.z;
        } else {
            t = make_float2(l.y, -l.x);
            sigma_d *= l.w;
        }

        float twoSigmaD2 = 2 * sigma_d * sigma_d;
        float twoSigmaR2 = 2 * sigma_r_ * sigma_r_;
        int halfWidth = int(ceilf( precision_ * sigma_d ));

        float2 tabs = fabs(t);
        float ds = 1.0f / ((tabs.x > tabs.y)? tabs.x : tabs.y);

        float norm = 1;
        for (float d = ds; d <= halfWidth; d += ds) {
            float2 dt = d * t;

            L.push_back(make_float3(0.5f + ix + dt.x, 0.5f + iy + dt.y, d));
            L.push_front(make_float3(0.5f + ix - dt.x, 0.5f + iy - dt.y, -d));
        }

        return std::vector<float3>(L.begin(), L.end());;
    }
void vm::scanner::device::ComputeIcpHelper::setLevelIntr(int level_index, float fx, float fy, float cx, float cy)
{
  int div = 1 << level_index;
  f = make_float2(fx/div, fy/div);
  c = make_float2(cx/div, cy/div);
  finv = make_float2(1.f/f.x, 1.f/f.y);
}
示例#4
0
 int oabf_sample_dir( int ix, int iy, const cpu_image& lfm_, bool tangential_ ) {
     float4 l = lfm_.at<float4>(ix, iy);
     float2 t;
     if (tangential_) {
         t = make_float2(l.x, l.y);
     } else {
         t = make_float2(l.y, -l.x);
     }
     float2 tabs = fabs(t);
     return (tabs.x > tabs.y)? 0 : 1;
 }
示例#5
0
// The kernel function of gravitation
__host__ __device__ inline
float2 kernelFunction(
    const float2 position_target,
    const float2 position_source,
    const float  weight_source
) {
  const float epsilon = 1e-1;
  float2 distance = make_float2(position_source.x - position_target.x, position_source.y - position_target.y);
  float r = sqrt(distance.x * distance.x + distance.y * distance.y);
  float tmp = weight_source / (r*r*r + epsilon);
  return make_float2(distance.x * tmp, distance.y * tmp);
}
InteractiveCamera::InteractiveCamera()
{
	centerPosition = Vector3Df(0, 0, 0);
	yaw = 0;
	pitch = 0.3;
	radius = 4;
	apertureRadius = 0.04; // 0.04
	focalDistance = 4.0f;

	resolution = make_float2(512, 512);  // width, height
	fov = make_float2(40, 40);
}
示例#7
0
void SPHSystem::add_particle(float2 pos, float2 vel)
{
	Particle *p=&(hMem[hParam->num_particle]);

	p->pos=pos;
	p->vel=vel;
	p->acc=make_float2(0.0f, 0.0f);
	p->ev=make_float2(0.0f, 0.0f);

	p->dens=hParam->rest_density;
	p->pres=0.0f;

	hParam->num_particle++;
}
示例#8
0
 std::vector<float3> stgauss3_path_( int ix, int iy, const cpu_image& st, float sigma,
                                    bool st_linear, bool adaptive, bool ustep,
                                    int order, float step_size )
 {
     cpu_sampler<float3> st_sampler(st, st_linear? cudaFilterModeLinear : cudaFilterModePoint);
     float2 p0 = make_float2(ix + 0.5f, iy + 0.5f);
     filter_path f(2 * sigma);
     if (!ustep) {
         if (order == 1) {
             if (adaptive)
                 st3_int<cpu_sampler<float3>,filter_path,1,true>(p0, st_sampler, f, st.w(), st.h(), step_size);
             else
                 st3_int<cpu_sampler<float3>,filter_path,1,false>(p0, st_sampler, f, st.w(), st.h(), step_size);
         } else {
             if (adaptive)
                 st3_int<cpu_sampler<float3>,filter_path,2,true>(p0, st_sampler, f, st.w(), st.h(), step_size);
             else
                 st3_int<cpu_sampler<float3>,filter_path,2,false>(p0, st_sampler, f, st.w(), st.h(), step_size);
         }
     } else {
         if (order == 1) {
             st3_int_ustep<cpu_sampler<float3>,filter_path,1>(p0, st_sampler, f, st.w(), st.h(), step_size);
         } else {
             st3_int_ustep<cpu_sampler<float3>,filter_path,2>(p0, st_sampler, f, st.w(), st.h(), step_size);
         }
     }
     return f.path();
 }
void ToolViewMouseHandler::Mouse(pangolin::View & v, pangolin::MouseButton button, int x, int y, bool pressed, int button_state) {
    pangolin::Handler::Mouse(v,button,x,y,pressed,button_state);

    switch(button) {
        case pangolin::MouseButtonLeft:
            if (!pressed) {

                const float2 toolboxPoint = make_float2(x - v.GetBounds().l,v.GetBounds().t() - y);
                ToolboxSection section = toolbox_->getSection(toolboxPoint);

                switch(section) {
                    case ButtonSection:
                        hasButtonSelection_ = true;
                        selectedButton_ = toolbox_->getButton(toolboxPoint);
                        break;
                    case LabelSection:
                        hasClassSelection_ = true;
                        selectedClass_ = toolbox_->getClass(toolboxPoint);
                        break;
                    case OverviewSection:
                        toolbox_->processOverviewCentering(toolboxPoint,v.GetBounds().w);
                        break;
                }

            }
            break;
        case pangolin::MouseWheelUp:
            toolbox_->processZoom(1.f/zoomSpeed_);
            break;
        case pangolin::MouseWheelDown:
            toolbox_->processZoom(zoomSpeed_);
            break;
    }

}
示例#10
0
static void blender_camera_init(BlenderCamera *bcam,
                                BL::RenderSettings& b_render)
{
	memset(bcam, 0, sizeof(BlenderCamera));

	bcam->type = CAMERA_PERSPECTIVE;
	bcam->zoom = 1.0f;
	bcam->pixelaspect = make_float2(1.0f, 1.0f);
	bcam->sensor_width = 32.0f;
	bcam->sensor_height = 18.0f;
	bcam->sensor_fit = BlenderCamera::AUTO;
	bcam->shuttertime = 1.0f;
	bcam->motion_position = Camera::MOTION_POSITION_CENTER;
	bcam->rolling_shutter_type = Camera::ROLLING_SHUTTER_NONE;
	bcam->rolling_shutter_duration = 0.1f;
	bcam->border.right = 1.0f;
	bcam->border.top = 1.0f;
	bcam->pano_viewplane.right = 1.0f;
	bcam->pano_viewplane.top = 1.0f;
	bcam->viewport_camera_border.right = 1.0f;
	bcam->viewport_camera_border.top = 1.0f;

	/* render resolution */
	bcam->full_width = render_resolution_x(b_render);
	bcam->full_height = render_resolution_y(b_render);

	/* pixel aspect */
	bcam->pixelaspect.x = b_render.pixel_aspect_x();
	bcam->pixelaspect.y = b_render.pixel_aspect_y();
}
示例#11
0
SPHSystem::SPHSystem()
{
	hParam=new SysParam();

	hParam->max_particle=10000;
	hParam->num_particle=0;

	hParam->kernel=0.04f;
	hParam->mass=0.02f;

	hParam->world_size=make_float2(2.56f, 2.56f);
	hParam->cell_size=hParam->kernel;
	hParam->grid_size.x=(uint)ceil(hParam->world_size.x/hParam->cell_size);
	hParam->grid_size.y=(uint)ceil(hParam->world_size.y/hParam->cell_size);
	hParam->tot_cell=hParam->grid_size.x*hParam->grid_size.y;

	hParam->gravity.x=0.0f; 
	hParam->gravity.y=-0.9f;
	hParam->wall_damping=-0.5f;
	hParam->rest_density=1000.0f;
	hParam->gas_constant=3.0f;
	hParam->viscosity=3.5f;
	hParam->time_step=0.003f;
	hParam->surf_normal=6.0f;
	hParam->surf_coe=0.2f;

	hParam->poly6_value=315.0f/(64.0f * PI * pow(hParam->kernel, 9));;
	hParam->spiky_value=-45.0f/(PI * pow(hParam->kernel, 6));
	hParam->visco_value=45.0f/(PI * pow(hParam->kernel, 6));

	hParam->grad_poly6=-945/(32 * PI * pow(hParam->kernel, 9));
	hParam->lplc_poly6=-945/(8 * PI * pow(hParam->kernel, 9));

	hParam->kernel_2=hParam->kernel*hParam->kernel;
	hParam->self_dens=hParam->mass*hParam->poly6_value*pow(hParam->kernel, 6);
	hParam->self_lplc_color=hParam->lplc_poly6*hParam->mass*(hParam->kernel_2)*(0-3/4*(hParam->kernel_2));

	sys_running=0;

	hMem=(Particle *)malloc(sizeof(Particle)*hParam->max_particle);
	alloc_array((void**)&(dMem), sizeof(Particle)*hParam->max_particle);
	hPoints=(float2 *)malloc(sizeof(float2)*hParam->max_particle);
	alloc_array((void**)&(dPoints), sizeof(float2)*hParam->max_particle);

	alloc_array((void**)&dHash, sizeof(uint)*hParam->max_particle);
	alloc_array((void**)&dIndex, sizeof(uint)*hParam->max_particle);
	alloc_array((void**)&dStart, sizeof(uint)*hParam->tot_cell);
	alloc_array((void**)&dEnd, sizeof(uint)*hParam->tot_cell);

	printf("Initialize SPH:\n");
	printf("World Width : %f\n", hParam->world_size.x);
	printf("World Height: %f\n", hParam->world_size.y);
	printf("Cell Size  : %f\n", hParam->cell_size);
	printf("Grid Width : %u\n", hParam->grid_size.x);
	printf("Grid Height: %u\n", hParam->grid_size.y);
	printf("Poly6 Kernel: %f\n", hParam->poly6_value);
	printf("Spiky Kernel: %f\n", hParam->spiky_value);
	printf("Visco Kernel: %f\n", hParam->visco_value);
	printf("Self Density: %f\n", hParam->self_dens);
}
void InteractiveCamera::buildRenderCamera(Camera* renderCamera){
	float xDirection = sin(yaw) * cos(pitch);
	float yDirection = sin(pitch);
	float zDirection = cos(yaw) * cos(pitch);
	glm::vec3 directionToCamera = glm::vec3(xDirection, yDirection, zDirection);
	glm::vec3 viewDirection = -directionToCamera;
	glm::vec3 eyePosition = centerPosition + directionToCamera * radius;

	renderCamera->position = make_float3(eyePosition[0], eyePosition[1], eyePosition[2]);
	renderCamera->view = make_float3(viewDirection[0], viewDirection[1], viewDirection[2]);
	renderCamera->up = make_float3(0, 1, 0);
	renderCamera->resolution = make_float2(resolution.x, resolution.y);
	renderCamera->fov = make_float2(fov.x, fov.y);
	renderCamera->apertureRadius = apertureRadius;
	renderCamera->focalDistance = radius;
}
示例#13
0
static void bssrdf_lookup_table_create(const BSSRDFParams *ss, vector<float>& sample_table, vector<float>& pdf_table)
{
	const int size = BSSRDF_RADIUS_TABLE_SIZE;
	vector<float> cdf(size);
	vector<float> pdf(size);
	float step = 1.0f/(float)(size - 1);
	float max_radius = bssrdf_lookup_table_max_radius(ss);
	float pdf_sum = 0.0f;

	/* compute the probability density function */
	for(int i = 0; i < pdf.size(); i++) {
		float x = (i*step)*max_radius;
		pdf[i] = bssrdf_cubic(ss->ld, x);
		pdf_sum += pdf[i];
	}

	/* adjust for area covered by each distance */
	for(int i = 0; i < pdf.size(); i++) {
		float x = (i*step)*max_radius;
		pdf[i] *= M_2PI_F*x;
	}

	/* normalize pdf, we multiply in reflectance later */
	if(pdf_sum > 0.0f)
		for(int i = 0; i < pdf.size(); i++)
			pdf[i] /= pdf_sum;

	/* sum to account for sampling which uses overlapping sphere */
	for(int i = pdf.size() - 2; i >= 0; i--)
		pdf[i] = pdf[i] + pdf[i+1];

	/* compute the cumulative density function */
	cdf[0] = 0.0f;

	for(int i = 1; i < size; i++)
		cdf[i] = cdf[i-1] + 0.5f*(pdf[i-1] + pdf[i])*step*max_radius;
	
	/* invert cumulative density function for importance sampling */
	float2 cdf_range = make_float2(0.0f, cdf[size - 1]);
	float2 table_range = make_float2(0.0f, max_radius);

	cdf_invert(sample_table, table_range, cdf, cdf_range);

	/* copy pdf table */
	for(int i = 0; i < pdf.size(); i++)
		pdf_table[i] = pdf[i];
}
示例#14
0
LDEVICE float2 BeckmannDistribution::DPDF( float3 N, float3 H ) const
{
    const float cos_theta = optix::dot( N, H );
    const float dee       = D( N, H );
    CHECK_FINITE( dee       ); 
    CHECK_FINITE( cos_theta ); 
    return make_float2( dee, dee/cos_theta);
}
void InteractiveCamera::buildRenderCamera(Camera* renderCamera){
	float xDirection = sin(yaw) * cos(pitch);
	float yDirection = sin(pitch);
	float zDirection = cos(yaw) * cos(pitch);
	Vector3Df directionToCamera = Vector3Df(xDirection, yDirection, zDirection);
	viewDirection = directionToCamera * (-1.0);
	Vector3Df eyePosition = centerPosition +directionToCamera * radius;
	//Vector3Df eyePosition = centerPosition; // rotate camera from stationary viewpoint
	

	renderCamera->position = eyePosition;
	renderCamera->view = viewDirection;
	renderCamera->up = Vector3Df(0, 1, 0);
	renderCamera->resolution = make_float2(resolution.x, resolution.y);
	renderCamera->fov = make_float2(fov.x, fov.y);
	renderCamera->apertureRadius = apertureRadius;
	renderCamera->focalDistance = focalDistance;
}
void ToolViewMouseHandler::MouseMotion(pangolin::View & v, int x, int y, int button_state) {

    const float2 toolboxPoint = make_float2(x - v.GetBounds().l,v.GetBounds().t() - y);
    ToolboxSection section = toolbox_->getSection(toolboxPoint);
    switch(section) {
        case OverviewSection:
            toolbox_->processOverviewCentering(toolboxPoint, v.GetBounds().w);
            break;
    }

}
示例#17
0
void
Projector::findProjectedCorners(
    float4 afCorners[4], 
    const float4 &rfRange,
    const float16 &rfInvViewPrj)
{
    float2 fMin = make_float2(rfRange.x, rfRange.y);
    float2 fMax = make_float2(rfRange.z, rfRange.w);

    afCorners[0] = make_float4(fMin.x, fMin.y, 0.0f, 1.0f);
    afCorners[1] = make_float4(fMax.x, fMin.y, 0.0f, 1.0f);
    afCorners[2] = make_float4(fMax.x, fMax.y, 0.0f, 1.0f);
    afCorners[3] = make_float4(fMin.x, fMax.y, 0.0f, 1.0f);

//    printf("Projected Grid: Find Projected Corners...\n");

    for (uint i = 0; i < 4; i++)
    {
        float4 fA = afCorners[i];
        float4 fB = afCorners[i];
        
        fA.z = -1.0f;
        fB.z = +1.0f;
        
        fA = rfInvViewPrj * fA;
        fB = rfInvViewPrj * fB;
        
        fB -= fA;
        
        float fT = -fA.y / fB.y;
        afCorners[i] = fA + fB * fT;

/*
        printf("[%2d] %8.5f %8.5f %8.5f %8.5f\n", i,
            afCorners[i].x / afCorners[i].w, 
            afCorners[i].y / afCorners[i].w, 
            afCorners[i].z / afCorners[i].w, 
            afCorners[i].w / afCorners[i].w);
*/
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Sync rendered View from blender scene to Octane camera data
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void BlenderSync::sync_view(BL::SpaceView3D b_v3d, BL::RegionView3D b_rv3d, int width, int height) {
    Camera* cam     = scene->camera;
    Camera  prevcam = *cam;

    cam->pixelaspect = make_float2(1.0f, 1.0f);

    float2 offset = {0};
    load_camera_from_view(cam, b_scene, b_v3d, b_rv3d, width, height, offset);
    cam->is_hidden = false;

    if(cam->modified(prevcam)) cam->tag_update();
} //sync_view()
示例#19
0
void DiagSplit::split_triangle(Patch *patch)
{
	TriangleDice::SubPatch sub_split;
	TriangleDice::EdgeFactors ef_split;

	sub_split.patch = patch;
	sub_split.Pu = make_float2(1.0f, 0.0f);
	sub_split.Pv = make_float2(0.0f, 1.0f);
	sub_split.Pw = make_float2(0.0f, 0.0f);

	ef_split.tu = T(patch, sub_split.Pv, sub_split.Pw);
	ef_split.tv = T(patch, sub_split.Pw, sub_split.Pu);
	ef_split.tw = T(patch, sub_split.Pu, sub_split.Pv);

	split(sub_split, ef_split);

	TriangleDice dice(params);

	for(size_t i = 0; i < subpatches_triangle.size(); i++) {
		TriangleDice::SubPatch& sub = subpatches_triangle[i];
		TriangleDice::EdgeFactors& ef = edgefactors_triangle[i];

		ef.tu = 4;
		ef.tv = 4;
		ef.tw = 4;

		ef.tu = max(ef.tu, 1);
		ef.tv = max(ef.tv, 1);
		ef.tw = max(ef.tw, 1);

		dice.dice(sub, ef);
	}

	subpatches_triangle.clear();
	edgefactors_triangle.clear();
}
示例#20
0
void oz::gpu_image::clear_white() {
    switch (format()) {
        case FMT_FLOAT:
            fill(1, 0, 0, w(), h());
            break;
        case FMT_FLOAT2:
            fill(make_float2(1), 0, 0, w(), h());
            break;
        case FMT_FLOAT3:
            fill(make_float3(1), 0, 0, w(), h());
            break;
        case FMT_FLOAT4:
            fill(make_float4(1), 0, 0, w(), h());
            break;
        default:
            OZ_INVALID_FORMAT();
    }
}
示例#21
0
std::vector<float3> gpu_stgauss2_path( int ix, int iy, const cpu_image<float4>& st, float sigma, float max_angle, 
                                       bool adaptive, bool st_linear, int order, float step_size )
{
    cpu_sampler<float4> st_sampler(st, st_linear? cudaFilterModeLinear : cudaFilterModePoint);
    float2 p0 = make_float2(ix + 0.5f, iy + 0.5f);
    if (adaptive) {
        float A = st2A(st(p0.x, p0.y));
        sigma *= 0.25f * (1 + A)*(1 + A);
    }
    std::deque<float3> C;
    float cos_max = cosf(radians(max_angle));
    stgauss2_path f(C, sigma);
    if (order == 1) st_integrate_euler(p0, st_sampler, f, cos_max, st.w(), st.h(), step_size);
    if (order == 2) st_integrate_rk2(p0, st_sampler, f, cos_max, st.w(), st.h(), step_size);
    if (order == 4) st_integrate_rk4(p0, st_sampler, f, cos_max, st.w(), st.h(), step_size);
    
    return std::vector<float3>(C.begin(), C.end());
}
示例#22
0
void SPHSystem::init_system()
{
	srand((unsigned int)time(NULL));

	float2 pos;
	float2 vel=make_float2(0.0f, 0.0f);

	for(pos.x=hParam->world_size.x*0.0f; pos.x<hParam->world_size.x*0.4f; pos.x+=(hParam->kernel*0.6f))
	{
		for(pos.y=hParam->world_size.y*0.0f; pos.y<hParam->world_size.y*0.9f; pos.y+=(hParam->kernel*0.6f))
		{
			add_particle(pos, vel);
		}
	}

	copy_array(dMem, hMem, sizeof(Particle)*hParam->num_particle, CUDA_HOST_TO_DEV);
	printf("Init Particle: %u\n", hParam->num_particle);
}
示例#23
0
static void blender_camera_init(BlenderCamera *bcam, BL::RenderSettings b_render, BL::Scene b_scene)
{
	memset(bcam, 0, sizeof(BlenderCamera));

	bcam->type = CAMERA_PERSPECTIVE;
	bcam->zoom = 1.0f;
	bcam->pixelaspect = make_float2(1.0f, 1.0f);
	bcam->sensor_width = 32.0f;
	bcam->sensor_height = 18.0f;
	bcam->sensor_fit = BlenderCamera::AUTO;
	bcam->shuttertime = 1.0f;
	bcam->border.right = 1.0f;
	bcam->border.top = 1.0f;
	bcam->pano_viewplane.right = 1.0f;
	bcam->pano_viewplane.top = 1.0f;

	/* render resolution */
	bcam->full_width = render_resolution_x(b_render);
	bcam->full_height = render_resolution_y(b_render);
}
示例#24
0
void plotPoints(Vec3f* dirs, unsigned int N)
{
	std::ostringstream str1, str2;
	str1 << "x = [";
	str2 << "y = [";
	for (size_t i = 0; i < N; i++)
	{
		dirs[i] = normalize(dirs[i]);
		float2 d = make_float2(dirs[i].x, dirs[i].y);
		str1 << d.x;
		str2 << d.y;
		if (i != N - 1)
		{
			str1 << ", ";
			str2 << ", ";
		}
	}
	str1 << "];";
	str2 << "];";
	str1 << "\n" << str2.str() << "\n" << "scatter(x,y,5)\ngrid on\naxis equal ";
	std::string plt = str1.str();
	toClipboard(plt);
}
示例#25
0
void vm::scanner::cuda::computeDists(const Depth& depth, Dists& dists, const Intr& intr)
{
  dists.create(depth.rows(), depth.cols());
  device::compute_dists(depth, dists, make_float2(intr.fx, intr.fy), make_float2(intr.cx, intr.cy));
}
示例#26
0
__device__  float2 convert2f2(const short2 s2O1_){ //can be called from host and device
	return make_float2(s2O1_.x, s2O1_.y);
}
示例#27
0
//----------------------------------------------------------------------------------------------------------------------
// This method should be overridden in user defined nodes.
// Recompute the given output based on the nodes inputs.
// The plug represents the data value that needs to be recomputed, and the data block holds the storage
// for all of the node'_scale attributes.
//----------------------------------------------------------------------------------------------------------------------
MStatus OceanNode::compute( const MPlug &_plug , MDataBlock &_data ){
    MStatus status;
    // see if we get the output plug
    if( _plug == m_output){    

        MDataHandle dataHandle;

        dataHandle = _data.inputValue(m_resolution, &status);
        CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get data handle for resolution plug");

        if (m_res != dataHandle.asInt()){
            switch(dataHandle.asInt()){
                case 0:
                    m_ocean->setResolution(128);
                    MGlobal::displayInfo("Resolution: 128");
                    break;
                case 1:
                    m_ocean->setResolution(256);
                    MGlobal::displayInfo("Resolution: 256");
                    break;
                case 2:
                    m_ocean->setResolution(512);
                    MGlobal::displayInfo("Resolution: 512");
                    break;
                case 3:
                    m_ocean->setResolution(1024);
                    MGlobal::displayInfo("Resolution: 1024");
                    break;
                default:
                    break;
            }
            m_res = dataHandle.asInt();
        }

        dataHandle = _data.inputValue( m_amplitude , &status );
        CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL( status , "Unable to get data handle for amplitude plug" );
        // now get the value for the data handle as a double
        double amp = dataHandle.asDouble();
        m_ocean->setAmplitude(amp);

        dataHandle = _data.inputValue(m_frequency, &status);
        CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get handle for \"frequency\" plug");
        double freq = dataHandle.asDouble();
        m_ocean->setFrequency(freq);

        dataHandle = _data.inputValue(m_windDirectionX, &status);
        CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get data handle for windDirectionX plug");
        // now get value for data handle
        double wdx = dataHandle.asDouble();
        dataHandle = _data.inputValue(m_windDirectionZ, &status);
        CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get data handle for windDirectionY plug");
        // now get value for data handle
        double wdz = dataHandle.asDouble();
        m_ocean->setWindVector(make_float2(wdx, wdz));

        dataHandle = _data.inputValue(m_windSpeed, &status);
        CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get data handle for windSpeed plug");
        // now get value for data handle
        double ws = dataHandle.asDouble();
        m_ocean->setWindSpeed(ws);

        // Only create a new frequency domain if either amplitude or the wind vecotr has changed
        if (m_amp != amp || m_wdx != wdx || m_wdz != wdz || m_ws != ws ){
            MGlobal::displayInfo("here");
            m_ocean->createH0();
            m_amp = amp;
            m_wdx = wdx;
            m_wdz = wdz;
            m_ws = ws;
        }

        dataHandle = _data.inputValue(m_choppiness, &status);
        CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get data handle for the choppiness plug");
        double choppiness = dataHandle.asDouble();

        dataHandle = _data.inputValue(m_time, &status);
        CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get data handle for time plug");
        MTime time = dataHandle.asTime();

        MDataHandle outputData = _data.outputValue(m_output, &status);
        CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL( status , "Unable to get data handle for output plug" );

        MFnMeshData mesh;
        MObject outputObject = mesh.create(&status);
        CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to create output mesh");

        // Find the current frame number we're on and create the grid based on this
        MAnimControl anim;
        anim.setMinTime(time);

        createGrid((int)pow(2.0, m_res+7), anim.currentTime().value()/24, choppiness, outputObject, status);

        CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to to create grid");

        outputData.set(outputObject);

        // clean the output plug, ie unset it from dirty so that maya does not re-evaluate it
        _data.setClean( _plug );

        return MStatus::kSuccess;
    }

    return MStatus::kUnknownParameter;
}
int extractManifold(const float4* p, int nPoints, float4& nearNormal, float4& centerOut,
                    int contactIdx[4])
{
    if( nPoints == 0 ) return 0;

    nPoints = min2( nPoints, 64 );

    float4 center = make_float4(0.f);
    {
        float4 v[64];
        memcpy( v, p, nPoints*sizeof(float4) );
        PARALLEL_SUM( v, nPoints );
        center = v[0]/(float)nPoints;
    }

    centerOut = center;

    {   //	sample 4 directions
        if( nPoints < 4 )
        {
            for(int i=0; i<nPoints; i++) contactIdx[i] = i;
            return nPoints;
        }

        float4 aVector = p[0] - center;
        float4 u = cross3( nearNormal, aVector );
        float4 v = cross3( nearNormal, u );
        u = normalize3( u );
        v = normalize3( v );

        int idx[4];

        float2 max00 = make_float2(0,FLT_MAX);
        {
            float4 dir0 = u;
            float4 dir1 = -u;
            float4 dir2 = v;
            float4 dir3 = -v;

            //	idx, distance
            {
                {
                    int4 a[64];
                    for(int ie = 0; ie<nPoints; ie++ )
                    {
                        float4 f;
                        float4 r = p[ie]-center;
                        f.x = dot3F4( dir0, r );
                        f.y = dot3F4( dir1, r );
                        f.z = dot3F4( dir2, r );
                        f.w = dot3F4( dir3, r );

                        a[ie].x = ((*(u32*)&f.x) & 0xffffff00);
                        a[ie].x |= (0xff & ie);

                        a[ie].y = ((*(u32*)&f.y) & 0xffffff00);
                        a[ie].y |= (0xff & ie);

                        a[ie].z = ((*(u32*)&f.z) & 0xffffff00);
                        a[ie].z |= (0xff & ie);

                        a[ie].w = ((*(u32*)&f.w) & 0xffffff00);
                        a[ie].w |= (0xff & ie);
                    }

                    for(int ie=0; ie<nPoints; ie++)
                    {
                        a[0].x = (a[0].x > a[ie].x )? a[0].x: a[ie].x;
                        a[0].y = (a[0].y > a[ie].y )? a[0].y: a[ie].y;
                        a[0].z = (a[0].z > a[ie].z )? a[0].z: a[ie].z;
                        a[0].w = (a[0].w > a[ie].w )? a[0].w: a[ie].w;
                    }

                    idx[0] = (int)a[0].x & 0xff;
                    idx[1] = (int)a[0].y & 0xff;
                    idx[2] = (int)a[0].z & 0xff;
                    idx[3] = (int)a[0].w & 0xff;
                }
            }

            {
                float2 h[64];
                PARALLEL_DO( h[ie] = make_float2((float)ie, p[ie].w), nPoints );
                REDUCE_MIN( h, nPoints );
                max00 = h[0];
            }
        }

        contactIdx[0] = idx[0];
        contactIdx[1] = idx[1];
        contactIdx[2] = idx[2];
        contactIdx[3] = idx[3];

//		if( max00.y < 0.0f )
//			contactIdx[0] = (int)max00.x;

        std::sort( contactIdx, contactIdx+4 );

        return 4;
    }
}
示例#29
0
void kf::cuda::computeDists(const Depth& depth, Dists& dists, const Intr& intr)
{
    dists.create(depth.rows(), depth.cols());
    impl::compute_dists(depth, dists, make_float2(intr.fx, intr.fy), make_float2(intr.cx, intr.cy));
}
示例#30
0
static bool ObtainCacheParticleUV(Mesh *mesh,
                                  BL::Mesh *b_mesh,
                                  BL::Object *b_ob,
                                  ParticleCurveData *CData,
                                  bool background,
                                  int uv_num)
{
  if (!(mesh && b_mesh && b_ob && CData))
    return false;

  CData->curve_uv.clear();

  BL::Object::modifiers_iterator b_mod;
  for (b_ob->modifiers.begin(b_mod); b_mod != b_ob->modifiers.end(); ++b_mod) {
    if ((b_mod->type() == b_mod->type_PARTICLE_SYSTEM) &&
        (background ? b_mod->show_render() : b_mod->show_viewport())) {
      BL::ParticleSystemModifier psmd((const PointerRNA)b_mod->ptr);
      BL::ParticleSystem b_psys((const PointerRNA)psmd.particle_system().ptr);
      BL::ParticleSettings b_part((const PointerRNA)b_psys.settings().ptr);

      if ((b_part.render_type() == BL::ParticleSettings::render_type_PATH) &&
          (b_part.type() == BL::ParticleSettings::type_HAIR)) {
        int totparts = b_psys.particles.length();
        int totchild = background ? b_psys.child_particles.length() :
                                    (int)((float)b_psys.child_particles.length() *
                                          (float)b_part.display_percentage() / 100.0f);
        int totcurves = totchild;

        if (b_part.child_type() == 0 || totchild == 0)
          totcurves += totparts;

        if (totcurves == 0)
          continue;

        int pa_no = 0;
        if (!(b_part.child_type() == 0) && totchild != 0)
          pa_no = totparts;

        int num_add = (totparts + totchild - pa_no);
        CData->curve_uv.reserve(CData->curve_uv.size() + num_add);

        BL::ParticleSystem::particles_iterator b_pa;
        b_psys.particles.begin(b_pa);
        for (; pa_no < totparts + totchild; pa_no++) {
          /* Add UVs */
          BL::Mesh::uv_layers_iterator l;
          b_mesh->uv_layers.begin(l);

          float2 uv = make_float2(0.0f, 0.0f);
          if (b_mesh->uv_layers.length())
            b_psys.uv_on_emitter(psmd, *b_pa, pa_no, uv_num, &uv.x);
          CData->curve_uv.push_back_slow(uv);

          if (pa_no < totparts && b_pa != b_psys.particles.end())
            ++b_pa;
        }
      }
    }
  }

  return true;
}