本文整理汇总了C++中SplineSurface::dimension方法的典型用法代码示例。如果您正苦于以下问题:C++ SplineSurface::dimension方法的具体用法?C++ SplineSurface::dimension怎么用?C++ SplineSurface::dimension使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplineSurface
的用法示例。
在下文中一共展示了SplineSurface::dimension方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SSurfTraceIsocontours
// ============================================================================
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;
}
示例2: main
int main(int argc, char* argv[] )
{
ALWAYS_ERROR_IF(argc < 3, "Usage: " << argv[0]
<< " inputsurf inputpoints" << endl);
// Open input surface file
ifstream is(argv[1]);
ALWAYS_ERROR_IF(is.bad(), "Bad or no input filename");
// Read surface from file
SplineSurface sf;
is >> sf;
// Get points
ifstream pts(argv[2]);
ALWAYS_ERROR_IF(pts.bad(), "Bad or no input filename");
int n;
pts >> n;
vector<double> pt(n*2);
for (int i = 0; i < n; ++i) {
pts >> pt[2*i] >> pt[2*i+1];
}
std::vector<Point> p(3, Point(sf.dimension()));
for (int i = 0; i < 10000; ++i) {
for (int j = 0; j < n; ++j) {
sf.point(p, pt[2*j], pt[2*j+1], 0);
}
}
// cout << p[0] << p[1] << p[2] << (p[1] % p[2]);
}
示例3: loftNonrationalSurface
//===========================================================================
SplineSurface*
LoftSurfaceCreator::loftSurfaceFromUnifiedCurves(vector<shared_ptr<SplineCurve> >::iterator
first_curve,
vector<double>::iterator first_param,
int nmb_crvs)
//===========================================================================
{
SplineSurface* surf = loftNonrationalSurface(first_curve, first_param, nmb_crvs);
if (first_curve[0]->rational())
{
int n = surf->numCoefs_u() * surf->numCoefs_v();
int kdim = surf->dimension() + 1;
bool all_positive = true;
vector<double>::const_iterator it = surf->rcoefs_begin();
it += (kdim - 1);
for (int i = 0; i < n; ++i)
if (it[kdim * i] <= 0.0)
{
all_positive = false;
break;
}
if (!all_positive)
{
delete surf;
surf = loftRationalSurface(first_curve, first_param, nmb_crvs);
}
}
return surf;
}
示例4: ASSERT
//===========================================================================
vector<shared_ptr<SplineSurface> >
SurfaceCreators::separateRationalParts(const SplineSurface& sf)
//===========================================================================
{
bool rat = sf.rational();
ASSERT(rat);
int dim= sf.dimension();
int rdim = dim + 1;
vector<shared_ptr<SplineSurface> > sep_sfs;
vector<double> coefs(sf.coefs_begin(), sf.coefs_end());
int nmb1 = sf.numCoefs_u();
int nmb2 = sf.numCoefs_v();
vector<double> rcoefs;
int num_coefs = nmb1*nmb2;
vector<double>::const_iterator rcoef_iter = sf.rcoefs_begin();
for (int ki = 0; ki < num_coefs; ++ki) {
rcoefs.push_back(rcoef_iter[ki*rdim+1]);
for (int kj = 0; kj < dim; ++kj) {
coefs[ki*dim+kj] /= (rcoefs.back());
}
}
sep_sfs.push_back(shared_ptr<SplineSurface>
(new SplineSurface(nmb1, nmb2, sf.order_u(), sf.order_v(),
sf.basis_u().begin(), sf.basis_v().begin(),
coefs.begin(), dim)));
sep_sfs.push_back(shared_ptr<SplineSurface>
(new SplineSurface(nmb1, nmb2, sf.order_u(), sf.order_v(),
sf.basis_u().begin(), sf.basis_v().begin(),
rcoefs.begin(), 1)));
return sep_sfs;
}
示例5: cart_to_bary
//==========================================================================
void cart_to_bary(const SplineSurface& sf, const BaryCoordSystem3D& bc,
SplineSurface& sf_bc)
//==========================================================================
{
ALWAYS_ERROR_IF(sf.dimension() != 3, "Dimension must be 3.");
int nu = sf.numCoefs_u();
int nv = sf.numCoefs_v();
Vector3D cart;
Vector4D bary;
vector<double> new_coefs;
if (!sf.rational()) {
new_coefs.resize(4 * nu * nv);
for (int iv = 0; iv < nv; ++iv) {
for (int iu = 0; iu < nu; ++iu) {
int offset = nu * iv + iu;
cart = Vector3D(sf.coefs_begin() + 3 * offset);
bary = bc.cartToBary(cart);
for (int j = 0; j < 4; ++j) {
new_coefs[4*offset + j] = bary[j];
}
}
}
} else {
new_coefs.resize(5 * nu * nv);
for (int iv = 0; iv < nv; ++iv) {
for (int iu = 0; iu < nu; ++iu) {
int offset = nu * iv + iu;
cart = Vector3D(sf.coefs_begin() + 3 * offset);
bary = bc.cartToBary(cart);
double w = sf.rcoefs_begin()[4*offset + 3];
for (int j = 0; j < 4; ++j) {
new_coefs[5*offset + j] = bary[j] * w;
}
new_coefs[5*offset + 4] = w;
}
}
}
sf_bc = SplineSurface(nu, nv, sf.order_u(), sf.order_v(),
sf.basis_u().begin(), sf.basis_v().begin(),
new_coefs.begin(), 4, sf.rational());
return;
}
示例6: main
int main(int argc, char** argv)
{
if (argc < 3) {
cerr << "Usage: " << argv[0] << " u_res v_res" << endl;
return 1;
}
int ures = atoi(argv[1]);
int vres = atoi(argv[2]);
ObjectHeader head;
cin >> head;
ASSERT(head.classType() == SplineSurface::classType());
SplineSurface sf;
cin >> sf;
vector<double> points;
vector<double> param_u;
vector<double> param_v;
sf.gridEvaluator(ures, vres, points, param_u, param_v);
RectGrid grid(ures, vres, sf.dimension(), &points[0]);
grid.writeStandardHeader(cout);
grid.write(cout);
}
示例7: main
int main(int argc, char** argv)
{
const string inp_curve_filename("approj_curve.g2");
cout << "\nRunning program '" << argv[0]
<< "'\nSpline curve filename= '"
<< inp_curve_filename.c_str() << "'." << endl;
// Read spline curve file
ifstream cfile(inp_curve_filename.c_str());
if (!cfile) {
cerr << "\nFile error. Could not open file: "
<< inp_curve_filename.c_str() << endl;
return 1;
}
shared_ptr<SplineCurve> curve(new SplineCurve);
ObjectHeader header;
cfile >> header;
if (!header.classType() == SplineCurve::classType()) {
THROW("Object type is NOT SplineCurve.");
}
cfile >> (*curve);
cfile.close();
// Print some curve information
Point pnt3d(3);
curve->point(pnt3d, curve->startparam());
cout << "\nSplineCurve: Dim= " << curve->dimension()
<< "\nStart. Param= " << curve->startparam() << " Point= "
<< pnt3d << endl;
curve->point(pnt3d, curve->endparam());
cout << "End. Param= " << curve->endparam() << " Point= "
<< pnt3d << endl;
cout << "Bounding box = " << curve->boundingBox() << endl;
// Create a surface by rotating the curve around the axis an angle of 2PI.
double angle = 2.0*M_PI;
Point point_on_axis(0.0, 5.0, 200.0);
Point axis_dir(1.0, 0.0, 0.0);
SplineSurface* surf =
SweepSurfaceCreator::rotationalSweptSurface(*curve, angle,
point_on_axis, axis_dir);
cout << "\nSurface: Dim= " << surf->dimension() << endl;
cout << "Bounding box = " << surf->boundingBox() << endl;
cout << "Point on axis = " << point_on_axis << endl;
cout << "Axis direction = " << axis_dir << endl;
// Open output file
ofstream fout("rotational_swept_surface.g2");
// Write curve to file. Colour=red.
fout << "100 1 0 4 255 0 0 255" << endl;
curve->write(fout);
// Write surface to file. Default colour=blue.
surf->writeStandardHeader(fout);
surf->write(fout);
// Write axis to file. Colour=green.
double dlength = 1.2*(surf->boundingBox().high()[0] -
surf->boundingBox().low()[0]);
Point endp = point_on_axis + dlength*axis_dir;
SplineCurve* axis = new SplineCurve(point_on_axis, endp);
fout << "100 1 0 4 0 255 0 255" << endl;
axis->write(fout);
// cout << "Open the file 'rotational_swept_surface.g2' in 'goview' to look"
// << " at the results" << endl;
delete surf;
delete axis;
return 0;
}
示例8: make_matrix
//==========================================================================
void make_matrix(const SplineSurface& surf, int deg,
vector<vector<double> >& mat)
//==========================================================================
{
// Create BernsteinMulti. In the rational case the weights are
// included in an "extra" coordinate.
int dim = surf.dimension();
bool rational = surf.rational();
vector<BernsteinMulti> beta;
spline_to_bernstein(surf, beta);
// Make vector of basis functions (with the surface plugged in) by
// using recursion
int num = (deg+1) * (deg+2) * (deg+3) / 6;
vector<BernsteinMulti> basis(num);
vector<BernsteinMulti> tmp(num);
basis[0] = BernsteinMulti(1.0);
BernsteinMulti zero_multi = BernsteinMulti(0.0);
for (int r = 1; r <= deg; ++r) {
int m = -1;
int tmp_num = (r + 1) * (r + 2) * (r + 3) / 6;
fill(tmp.begin(), tmp.begin() + tmp_num, zero_multi);
for (int i = 0; i < r; ++i) {
int k = (i + 1) * (i + 2) / 2;
for (int j = 0; j <= i; ++j) {
for (int l = 0; l <= j; ++l) {
++m;
tmp[m] += beta[0] * basis[m];
tmp[m + k] += beta[1] * basis[m];
tmp[m + 1 + j + k] += beta[2] * basis[m];
tmp[m + 2 + j + k] += beta[3] * basis[m];
}
}
}
basis.swap(tmp);
}
// Fill up the matrix mat
int deg_u = surf.order_u() - 1;
int deg_v = surf.order_v() - 1;
int numbas = (deg * deg_u + 1) * (deg * deg_v + 1);
mat.resize(numbas);
for (int row = 0; row < numbas; ++row) {
mat[row].resize(num);
for (int col = 0; col < num; ++col) {
mat[row][col] = basis[col][row];
}
}
// If rational, include diagonal scaling matrix. Dividing the
// D-matrix by the weights has the same effect as multiplying the
// basis with the same weights. (Included for numerical reasons only -
// it makes the basis a partition of unity.)
if (rational) {
BernsteinMulti weights = BernsteinMulti(1.0);
for (int i = 1; i <= deg; ++i)
weights *= beta[dim];
for (int row = 0; row < numbas; ++row) {
double scaling = 1.0 / weights[row];
for (int col = 0; col < num; ++col) {
mat[row][col] *= scaling;
}
}
}
// // Check Frobenius norm
// double norm = 0.0;
// for (int irow = 0; irow < numbas; ++irow) {
// for (int icol = 0; icol < num; ++icol) {
// norm += mat[irow][icol] * mat[irow][icol];
// }
// }
// norm = sqrt(norm);
// cout << "Frobenius norm = " << norm << endl;
return;
}
示例9: main
int main(int argc, char** argv)
{
if (argc != 6)
{
cout << "Usage: " << argv[0] << " surfaceinfile surface3doutfile points3doutfile num_u num_v" << endl;
exit(-1);
}
ifstream filein(argv[1]);
ALWAYS_ERROR_IF(filein.bad(), "Bad or no curvee input filename");
ObjectHeader head;
filein >> head;
if (head.classType() != SplineSurface::classType()) {
THROW("Not a spline surface");
}
SplineSurface sf;
filein >> sf;
ofstream fileoutsurf(argv[2]);
ALWAYS_ERROR_IF(fileoutsurf.bad(), "Bad surface output filename");
ofstream fileoutpts(argv[3]);
ALWAYS_ERROR_IF(fileoutpts.bad(), "Bad points output filename");
int num_u = atoi(argv[4]);
int num_v = atoi(argv[5]);
vector<double> pts, param_u, param_v;
sf.gridEvaluator(num_u, num_v, pts, param_u, param_v);
vector<double> coefs3d;
vector<Point> pts3d;
int dim = sf.dimension();
bool rational = sf.rational();
int ctrl_pts = sf.numCoefs_u() * sf.numCoefs_v();
vector<double>::const_iterator it = sf.ctrl_begin();
for (int i = 0; i < ctrl_pts; ++i)
{
if (dim <= 3)
for (int j = 0; j < 3; ++j)
{
if (j>=dim)
coefs3d.push_back(0.0);
else
{
coefs3d.push_back(*it);
++it;
}
}
else
{
for (int j = 0; j < 3; ++j, ++it)
coefs3d.push_back(*it);
it += (dim-3);
}
if (rational)
{
coefs3d.push_back(*it);
++it;
}
}
int pts_pos = 0;
for (int i = 0; i < num_u*num_v; ++i)
{
double x, y, z;
if (dim == 0)
x = 0.0;
else
x = pts[pts_pos];
if (dim <= 1)
y = 0.0;
else
y = pts[pts_pos+1];
if (dim <= 2)
z = 0.0;
else
z = pts[pts_pos+2];
pts_pos += dim;
pts3d.push_back(Point(x, y, z));
}
SplineSurface sf3d(sf.basis_u(), sf.basis_v(), coefs3d.begin(), 3, rational);
sf3d.writeStandardHeader(fileoutsurf);
sf3d.write(fileoutsurf);
fileoutpts << "400 1 0 4 255 255 0 255" << endl;
fileoutpts << pts3d.size() << endl;
for (int i = 0; i < (int)pts3d.size(); ++i)
fileoutpts << pts3d[i] << endl;
}
示例10: refinedBezierCoefsCubic
//===========================================================================
void SplineUtils::refinedBezierCoefsCubic(SplineSurface& spline_sf,
int ind_u_min, int ind_v_min,
vector<double>& bez_coefs)
//===========================================================================
{
assert(!spline_sf.rational());
if (bez_coefs.size() != 48)
bez_coefs.resize(48);
std::fill(bez_coefs.begin(), bez_coefs.end(), 0.0);
// Values for inpute spline surface.
int dim = spline_sf.dimension();
int order_u = spline_sf.order_u();
int order_v = spline_sf.order_u();
int num_coefs_u = spline_sf.numCoefs_u();
int num_coefs_v = spline_sf.numCoefs_v();
// Checking that input index is within range.
assert(ind_u_min >= order_u - 1 && ind_u_min < num_coefs_u);
assert(ind_v_min >= order_v - 1 && ind_v_min < num_coefs_v);
BsplineBasis& basis_u = spline_sf.basis_u();
BsplineBasis& basis_v = spline_sf.basis_v();
double* knot_u = &basis_u.begin()[0];
double* knot_v = &basis_v.begin()[0];
// We expect the knot index to refer to the last occurence.
assert(knot_u[ind_u_min] != knot_u[ind_u_min+1]);
assert(knot_v[ind_v_min] != knot_v[ind_v_min+1]);
// We expect knot mult to be 1 or 4.
int knot_mult_umin = (knot_u[ind_u_min-1] == knot_u[ind_u_min]) ? 4 : 1;
int knot_mult_umax = (knot_u[ind_u_min+1] == knot_u[ind_u_min+2]) ? 4 : 1;
int knot_mult_vmin = (knot_v[ind_v_min-1] == knot_v[ind_v_min]) ? 4 : 1;
int knot_mult_vmax = (knot_v[ind_v_min+1] == knot_v[ind_v_min+2]) ? 4 : 1;
bool kreg_at_ustart = (knot_mult_umin == 4);
bool kreg_at_uend = (knot_mult_umax == 4);
vector<double> transf_mat_u(16, 0.0);
// if (!kreg_at_ustart && !kreg_at_uend)
splineToBezierTransfMat(knot_u + ind_u_min - 3,
transf_mat_u);
#ifndef NDEBUG
std::cout << "\ntransf_mat_u=" << std::endl;
for (size_t kj = 0; kj < 4; ++kj)
{
for (size_t ki = 0; ki < 4; ++ki)
std::cout << transf_mat_u[kj*4+ki] << " ";
std::cout << std::endl;
}
std::cout << std::endl;
#endif // NDEBUG
// else
// cubicTransfMat(knot_u + ind_u_min - 3,
// kreg_at_ustart, kreg_at_uend,
// transf_mat_u);
bool kreg_at_vstart = (knot_mult_vmin == 4);
bool kreg_at_vend = (knot_mult_vmax == 4);
vector<double> transf_mat_v(16, 0.0);
// if (!kreg_at_ustart && !kreg_at_uend)
splineToBezierTransfMat(knot_v + ind_v_min - 3,
transf_mat_v);
#ifndef NDEBUG
std::cout << "\ntransf_mat_v=" << std::endl;
for (size_t kj = 0; kj < 4; ++kj)
{
for (size_t ki = 0; ki < 4; ++ki)
std::cout << transf_mat_v[kj*4+ki] << " ";
std::cout << std::endl;
}
std::cout << std::endl;
#endif // NDEBUG
extractBezierCoefs(&spline_sf.coefs_begin()[0],
num_coefs_u, num_coefs_v,
ind_u_min, ind_v_min,
transf_mat_u, transf_mat_v,
bez_coefs);
return;
}