コード例 #1
0
ntk::Polygon2d apply_transform(const ntk::AffineTransform& transform, const cv::Rect_<float>& rect)
{
  ntk::Polygon2d output;

  {
    cv::Point2f p (rect.x, rect.y);
    p = apply_transform(transform, p);
    output.points[0].push_back(p);
  }

  {
    cv::Point2f p (rect.x+rect.width, rect.y);
    p = apply_transform(transform, p);
    output.points[0].push_back(p);
  }

  {
    cv::Point2f p (rect.x+rect.width, rect.y+rect.height);
    p = apply_transform(transform, p);
    output.points[0].push_back(p);
  }

  {
    cv::Point2f p (rect.x, rect.y+rect.height);
    p = apply_transform(transform, p);
    output.points[0].push_back(p);
  }

  return output;
}
コード例 #2
0
// ============================================================================
vector<CurveVec> SSurfTraceIsocontours(const SplineSurface& ss,
				       const vector<double>& isovals,
				       const double tol, 
				       bool include_3D_curves,
				       bool use_sisl_marching)
// ============================================================================
{
  assert(ss.dimension() == 1); // only intended to work for spline functions
  
  // Compute topology for each requested level-set.  We use SISL for this
  SISLSurf* sislsurf1D = GoSurf2SISL(ss, false);
  SISLSurf* sislsurf3D = use_sisl_marching ? make_sisl_3D(ss) : nullptr;
  
  // Defining function tracing out the level set for a specified isovalue
  const function<CurveVec(double)> comp_lset = [&] (double ival)
    {return compute_levelset(ss, sislsurf1D, sislsurf3D, ival, tol,
			     include_3D_curves, use_sisl_marching);};

  // Computing all level-set curves for all isovalues ("transforming" each
  // isovalue into its corresponding level-set)
  const vector<CurveVec> result = apply_transform(isovals, comp_lset);

  // Cleaning up after use of SISL objects
  freeSurf(sislsurf1D);
  if (sislsurf3D)
    freeSurf(sislsurf3D);

  // Returning result
  return result;
}
コード例 #3
0
ファイル: test.c プロジェクト: WFT/l3d
void render_spin_test() {
  Matrix *faces = mat_construct(0, 4);
  double col[4] = {0, 0, 0, 1};
  double eye[3] = {0, 0, 100};
  screen = malloc(4 * sizeof(double));
  screen[0] = -10;
  screen[1] = -10;
  screen[2] = 10;
  screen[3] = 10;
  if (init_live_render(600, 600))
    printf("live rendering setup failed... Exiting now.\n");
  clock_t t;
  double rad = rand_radian();
  unsigned long i;
  double white[3] = {1, 1, 1};
  Matrix *color = mat_construct(0, 3);
  do {
    for (i=0; i < 3000; i++) {
      rand_point(col);
      mat_add_column(faces, col);
      mat_add_column(color, white);
    }
    t = clock();
    apply_transform(rotate_y_mat(rad), &faces);
    rendercyclops(faces, eye, color);
    t = clock() - t;
    printf("%d faces spun in %f seconds\n", faces->cols/3, ((float)t)/CLOCKS_PER_SEC);
  } while (((float)t)/CLOCKS_PER_SEC < 1);
  renderppm("test.ppm");
  mat_destruct(faces);
}
コード例 #4
0
 void translate(Points *p, Point translation) {
     Matrix t(4, 4);
     t.data()[0][3] = translation.x;
     t.data()[1][3] = translation.y;
     t.data()[2][3] = translation.z;
     t.data()[3][3] = 1.0;
     apply_transform(p, &t);
 }
コード例 #5
0
    void rotate(Points *p, Line axis, float degrees) {

        if (degrees == 0.0)
            return;

        float rads = degrees*M_PI/180.0;
        //float sign = (rads >= 0) ? -1.0 : 1.0;

        rads = fabs(rads);

        // Do not return points
        Point p1 = axis.a;
        Point p2 = axis.b;

        if (magnitude(p1) > magnitude(p2))
            swap(p1, p2);

        Point d = unit_length(Line(p1, p2));

        if (isnan(d.x) || isnan(d.y) || isnan(d.z))
            return;

        float u = d.x;
        float v = d.y;
        float w = d.z;
        float a = p1.x;
        float b = p1.y;
        float c = p1.z;

        Matrix *M = new Matrix(4, 4);
        M->data()[0][0] = u*u + (v*v + w*w) * cos(rads);
        M->data()[0][1] = u*v*(1-cos(rads)) - w*sin(rads);
        M->data()[0][2] = u*w*(1-cos(rads)) + v*sin(rads);
        M->data()[0][3] = (a*(v*v + w*w) - u*(b*v + c*w))*(1-cos(rads)) + (b*w - c*v)*sin(rads);

        M->data()[1][0] = u*v*(1-cos(rads)) + w*sin(rads);
        M->data()[1][1] = v*v + (u*u + w*w)*cos(rads);
        M->data()[1][2] = v*w*(1-cos(rads)) - u*sin(rads);
        M->data()[1][3] = (b*(u*u + w*w) - v*(a*u + c*w))*(1-cos(rads)) + (c*u - a*w)*sin(rads);

        M->data()[2][0] = u*w*(1-cos(rads)) - v*sin(rads);
        M->data()[2][1] = v*w*(1-cos(rads)) + u*sin(rads);
        M->data()[2][2] = w*w + (u*u + v*v)*cos(rads);
        M->data()[2][3] = (c*(u*u + v*v) - w*(a*u + b*v))*(1-cos(rads)) + (a*v - b*u)*sin(rads);

        M->data()[3][0] = 0;
        M->data()[3][1] = 0;
        M->data()[3][2] = 0;
        M->data()[3][3] = 1;

        apply_transform(p, M);

        delete M;

    }
コード例 #6
0
ファイル: colinfo.cpp プロジェクト: hattorishizuko/openhrp3
void ColModel::apply_all_transforms(TransformNode* tnode, Node* cur, fVec3& pos)
{
    Node* node;
    int scale_only = false;
    for(node=cur; node; node=node->getParentNode())
    {
        if(node->isTransformNode())
        {
            // if node is the top transform node, apply scale only and break
            if(node == tnode)
                scale_only = true;
            apply_transform((TransformNode*)node, pos, scale_only);
        }
    }
}
コード例 #7
0
ファイル: test.c プロジェクト: WFT/l3d
void spin_test() {
  Matrix *faces = mat_construct(0, 4);
  double col[4] = {0, 0, 0, 1};
  clock_t t;
  double rad = rand_radian();
  unsigned long i;
  do {
    for (i=0; i < 3000; i++) {
      rand_point(col);
      mat_add_column(faces, col);
    }
    t = clock();
    apply_transform(rotate_z_mat(rad), &faces);
    t = clock() - t;
    printf("%d faces spun in %f seconds\n", faces->cols/3,((float)t)/CLOCKS_PER_SEC);
  } while (((float)t)/CLOCKS_PER_SEC < 1);
  mat_destruct(faces);
}
コード例 #8
0
    void scale(Points *p, float factor) {
        Matrix *t = new Matrix(4, 4);

        t->data()[0][0] = 1;
        t->data()[1][1] = 1;
        t->data()[2][2] = 1;

        t->data()[0][0] *= factor;
        t->data()[1][1] *= factor;
        t->data()[2][2] *= factor;

        Point c_i = find_centroid(p);
        Point c = { -1*c_i.x, -1*c_i.y, -1*c_i.z };

        translate(p, c); // Move/translate to origin
        apply_transform(p, t);
        translate(p,  c_i); // Apply translate inverse

        delete t;

    }
コード例 #9
0
ファイル: texturesource.cpp プロジェクト: caomw/appleseed
Color4f TextureSource::sample_texture(
    TextureCache&               texture_cache,
    const Vector2d&             uv) const
{
    // Start with the transformed input texture coordinates.
    Vector2d p = apply_transform(uv);
    p.y = 1.0 - p.y;

    // Apply the texture addressing mode.
    apply_addressing_mode(m_texture_instance.get_addressing_mode(), p);

    switch (m_texture_instance.get_filtering_mode())
    {
      case TextureFilteringNearest:
        {
            p.x = clamp(p.x * m_scalar_canvas_width, 0.0, m_max_x);
            p.y = clamp(p.y * m_scalar_canvas_height, 0.0, m_max_y);

            const size_t ix = truncate<size_t>(p.x);
            const size_t iy = truncate<size_t>(p.y);

            return get_texel(texture_cache, ix, iy);
        }

      case TextureFilteringBilinear:
        {
            p.x *= m_max_x;
            p.y *= m_max_y;

            const int ix = truncate<int>(p.x);
            const int iy = truncate<int>(p.y);

            // Retrieve the four surrounding texels.
            Color4f t00, t10, t01, t11;
            get_texels_2x2(
                texture_cache,
                ix, iy,
                t00, t10, t01, t11);

            // Compute weights.
            const float wx1 = static_cast<float>(p.x - ix);
            const float wy1 = static_cast<float>(p.y - iy);
            const float wx0 = 1.0f - wx1;
            const float wy0 = 1.0f - wy1;

            // Apply weights.
            t00 *= wx0 * wy0;
            t10 *= wx1 * wy0;
            t01 *= wx0 * wy1;
            t11 *= wx1 * wy1;

            // Accumulate.
            t00 += t10;
            t00 += t01;
            t00 += t11;

            return t00;
        }

      default:
        assert(!"Wrong texture filtering mode.");
        return Color4f(0.0f);
    }
}
コード例 #10
0
ファイル: align.c プロジェクト: wolneykien/xrandr-align
int
align (Display *display,
       int argc,
       const char *argv[],
       const char *funcname,
       const char *usage)
{
    RROutput outputid;
    XRROutputInfo *output;
    int ret;
    const char *inputarg;
    int screen;
    const char *pre_script;
    const char *post_script;

    ret = get_screen (display, argc, argv, funcname, usage, &screen);
    if (ret == EXIT_FAILURE) {
        return ret;
    }

    ret = get_argval (argc, argv, "input", funcname, usage, "Virtual core pointer", &inputarg);
    if (ret == EXIT_FAILURE) {
        return ret;
    }

    ret = get_output (display, argc, argv, funcname, usage, &outputid, &output);
    if (ret == EXIT_FAILURE) {
        return ret;
    }

    ret = get_argval (argc, argv, "pre-script", funcname, usage, "", &pre_script);
    if (ret == EXIT_FAILURE) {
        return ret;
    }

    ret = get_argval (argc, argv, "post-script", funcname, usage, "", &post_script);
    if (ret == EXIT_FAILURE) {
        return ret;
    }

    if (ret != EXIT_FAILURE) {
        Window root;

        if (verbose) {
            fprintf (stderr, "Output: %s\n", output->name);
        }

        root = RootWindow (display, screen);

        ret = run_script (pre_script);
        if (ret != EXIT_FAILURE) {
            ret = apply_transform (display, root, output->crtc, inputarg);
            if (ret != EXIT_FAILURE) {
                ret = run_script (post_script);
            }
        }
    }

    XRRFreeOutputInfo (output);
    return ret;
}