本文整理汇总了C++中Paths::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ Paths::resize方法的具体用法?C++ Paths::resize怎么用?C++ Paths::resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Paths
的用法示例。
在下文中一共展示了Paths::resize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadFromFile
bool LoadFromFile(Paths &ppg, char * filename, double scale= 1,
int xOffset = 0, int yOffset = 0)
{
ppg.clear();
FILE *f = fopen(filename, "r");
if (!f) return false;
int polyCnt, vertCnt;
char junk [80];
double X, Y;
if (fscanf(f, "%d", &polyCnt) == 1 && polyCnt > 0)
{
ppg.resize(polyCnt);
for (int i = 0; i < polyCnt; i++) {
if (fscanf(f, "%d", &vertCnt) != 1 || vertCnt <= 0) break;
ppg[i].resize(vertCnt);
for (int j = 0; j < vertCnt; j++) {
if (fscanf(f, "%lf%*[, ]%lf", &X, &Y) != 2) break;
ppg[i][j].X = Round((X + xOffset) * scale);
ppg[i][j].Y = Round((Y + yOffset) * scale);
fgets(junk, 80, f);
}
}
}
fclose(f);
return true;
}
示例2: MakeRandomPoly
void MakeRandomPoly(int edgeCount, int width, int height, Paths & poly)
{
poly.resize(1);
poly[0].resize(edgeCount);
for (int i = 0; i < edgeCount; i++){
poly[0][i].X = rand() % width;
poly[0][i].Y = rand() % height;
}
}
示例3: if
void
mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
mxArray *par; // ptr to mxArray structure
double *pda; // ptr to polynomial data
double *pud; // pointer to unit conversion factor
mxLogical *ph; // pointer to hole flags
double ud, iud;
unsigned int Na, Nb, vnu;
unsigned int k, m;
ClipType pop;
char ostr[STR_LEN]; //string with polygon operation
//////////////////
// check arguments
//
// argument number
if (nrhs != 4) {
mexErrMsgTxt("polyboolmex : expected 4 input arguments.");
}
// argument pa
if ( !mxIsCell(prhs[0]) ) {
mexErrMsgTxt("polyboolmex : argument pa must be a cell array.");
}
Na = mxGetM(prhs[0])*mxGetN(prhs[0]);
if (!Na) {
mexErrMsgTxt("polyboolmex : no input polygons pa.");
}
// argument pb
if ( !mxIsCell(prhs[1]) ) {
mexErrMsgTxt("polyboolmex : argument pb must be a cell array.");
}
Nb = mxGetM(prhs[1])*mxGetN(prhs[1]);
if (!Nb) {
mexErrMsgTxt("polyboolmex : no input polygons pb.");
}
// get operation argument
mxGetString(prhs[2], ostr, STR_LEN);
if ( !strncmp(ostr, "or", 2) )
pop = ctUnion;
else if ( !strncmp(ostr, "and", 3) )
pop = ctIntersection;
else if ( !strncmp(ostr, "notb", 4) )
pop = ctDifference;
else if ( !strncmp(ostr, "diff", 4) )
pop = ctDifference;
else if ( !strncmp(ostr, "xor", 3) )
pop = ctXor;
else {
mexErrMsgTxt("polyboolmex : unknown boolean set algebra operation.");
}
// conversion factor argument
pud = (double*)mxGetData(prhs[3]);
ud = *pud;
iud = 1.0/ud;
////////////////////////
// copy and prepare data
//
// pa
pa.resize(Na);
for (k=0; k<Na; k++) {
// get the next polygon from the cell array
par = mxGetCell(prhs[0], k); // ptr to mxArray
if ( mxIsEmpty(par) ) {
mexErrMsgTxt("poly_boolmex : empty polygon in pa.");
}
pda = (double*)mxGetData(par); // ptr to a data
vnu = mxGetM(par); // rows = vertex number
// copy polygon and transpose, scale
pa[k].resize(vnu);
for (m=0; m<vnu; m++) {
pa[k][m].X = (cInt)(ud * pda[m] + 0.5);
pa[k][m].Y = (cInt)(ud * pda[m+vnu] + 0.5);
}
// make sure polygons have positive orientation
if ( !Orientation(pa[k]) )
ReversePath(pa[k]);
}
// pb
pb.resize(Nb);
for (k=0; k<Nb; k++) {
// get the next polygon
par = mxGetCell(prhs[1], k); // ptr to mxArray
if ( mxIsEmpty(par) ) {
mexErrMsgTxt("poly_boolmex : empty polygon in pb.");
//.........这里部分代码省略.........
示例4: main
int main(int argc, char *argv[])
{
// Set the current locale.
setlocale(LC_ALL, "");
// Set the text message domain.
bindtextdomain("tilesetter", LOCALE_DIR);
textdomain("tilesetter");
static const char* version = "0.1";
std::cout << boost::format(_("Tilesetter version %1%")) % version << std::endl;
std::cout << _(
"Copyright (C) 2009 by Tamino Dauth\n"
"[email protected]\n"
"\n"
"This program is free software; you can redistribute it and/or modify\n"
"it under the terms of the GNU General Public License as published by\n"
"the Free Software Foundation; either version 2 of the License, or\n"
"(at your option) any later version.\n"
"\n"
"This program is distributed in the hope that it will be useful,\n"
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
"GNU General Public License for more details.\n"
"\n"
"You should have received a copy of the GNU General Public License\n"
"along with this program; if not, write to the\n"
"Free Software Foundation, Inc.,\n"
"59 Temple Place - Suite 330, Boston, MA 02111-1307, USA."
) << std::endl;
typedef std::vector<boost::filesystem::path> Paths;
typedef std::vector<std::string> Strings;
// TODO throws exception when using escaped white spaces! - string work around
Strings environmentStrings;
Paths environments;
const boost::program_options::command_line_style::style_t pstyle = boost::program_options::command_line_style::style_t(
boost::program_options::command_line_style::unix_style
);
boost::program_options::options_description desc("Allowed options");
desc.add_options()
("version,V", _("Shows current version of tilesetter."))
("help,h",_("Shows this text."))
// options
// operations
("reassign,r", _("Reads ground and cliff types from the first environment file and assigns them to all following."))
// input
("files,f", boost::program_options::value<Strings>(&environmentStrings), _("Expected environment files."))
;
boost::program_options::positional_options_description p;
p.add("files", -1);
boost::program_options::variables_map vm;
try
{
boost::program_options::store(boost::program_options::command_line_parser(argc, argv).style(pstyle).options(desc).positional(p).run(), vm);
}
catch (std::exception &exception)
{
std::cerr << boost::format(_("Error while parsing program options: \"%1%\"")) % exception.what() << std::endl;
return EXIT_FAILURE;
}
boost::program_options::notify(vm);
// WORKAROUND
environments.resize(environmentStrings.size());
environments.assign(environmentStrings.begin(), environmentStrings.end());
if (vm.count("version"))
{
std::cout << boost::format(_(
"tilesetter %1%.\n"
"Copyright © 2009 Tamino Dauth\n"
"License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>\n"
"This is free software: you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law."
)) % version << std::endl;
return EXIT_SUCCESS;
}
if (vm.count("help"))
{
std::cout << desc << std::endl;
std::cout << _("\nReport bugs to [email protected] or on https://wc3lib.org") << std::endl;
return EXIT_SUCCESS;
}
if (environments.empty())
{
std::cerr << _("Missing environments arguments.") << std::endl;
//.........这里部分代码省略.........