本文整理汇总了C++中std::vector::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ vector::reserve方法的具体用法?C++ vector::reserve怎么用?C++ vector::reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::vector
的用法示例。
在下文中一共展示了vector::reserve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: averagePoint
void Polyhedron<Real>::addConvexPointToPolyhedron(
const std::vector<plane<Real >> &planes,
const std::vector<vector3<Real >> &vertices,
const std::vector<PolyhedronEdge> &edges,
const vector3<Real> &spot,
std::vector<plane<Real >> &new_planes,
std::vector<vector3<Real >> &new_vertices,
std::vector<PolyhedronEdge> &new_edges)
{
//TODO wyprofilować i zoptymalizować
/*
założenia:
1) żaden wierzchołek się nie powtarza
2) żadna płaszczyzna się nie powtarza
*/
vector3<Real> averagePoint(vector3<Real>::zero);
Real scale = ((Real) 1.0) / vertices.size();
for (uint i = 0; i < vertices.size(); ++i)
averagePoint += vertices[i] * scale;
new_vertices.reserve(vertices.size() + 1);
new_vertices.clear();
new_vertices.push_back(spot);
int num_spot = 0; // new_vertices.size() -1;
new_edges.clear();
new_planes.clear();
std::vector<bool> isPlaneUseful(planes.size());
std::vector<int> oldNewVertexMapping(vertices.size());
std::vector<int> oldNewPlaneMapping(planes.size());
/*
klucz - indeks starego wierzchołka (!= spot) nowej krawędzi
wartość - druga ściana która wspóldzieli nową krawędź lub pusta gdy nieznana
*/
std::map<int, int> oldEdgesToNewWalls;
for (uint i = 0; i < oldNewVertexMapping.size(); ++i)
oldNewVertexMapping[i] = -1; //unused
for (uint i = 0; i < oldNewPlaneMapping.size(); ++i)
oldNewPlaneMapping[i] = -1; //unused
for (uint i = 0; i < planes.size(); ++i)
{
bool planeUseful = (planes[i].distance(spot) >= -std::max(error, std::fabs(error * planes[i].d)));
isPlaneUseful[i] = planeUseful;
if (planeUseful)
{
new_planes.push_back(planes[i]);
oldNewPlaneMapping[i] = new_planes.size() - 1;
}
}
for (uint i = 0; i < edges.size(); ++i)
{
char usefulness = 0;
if (isPlaneUseful[edges[i].num_p1])
usefulness++;
if (isPlaneUseful[edges[i].num_p2])
usefulness++;
if (usefulness == 0)
continue;
/*
wierczhołkom mogły pozmieniać się numery, następne 10 linijek to
załatwia
*/
int new_num_v1 = oldNewVertexMapping[edges[i].num_v1];
if (new_num_v1 == -1)
{
new_vertices.push_back(vertices[edges[i].num_v1]);
new_num_v1 = new_vertices.size() - 1;
oldNewVertexMapping[edges[i].num_v1] = new_num_v1;
}
int new_num_v2 = oldNewVertexMapping[edges[i].num_v2];
if (new_num_v2 == -1)
{
new_vertices.push_back(vertices[edges[i].num_v2]);
new_num_v2 = new_vertices.size() - 1;
oldNewVertexMapping[edges[i].num_v2] = new_num_v2;
}
/*
płaszczyznom też mogły się zmienić numery, ale tu test na -1
(wyrzucenie złej płaszczyzny) zanużymy w podprzypadku.
*/
int new_num_p1 = oldNewPlaneMapping[edges[i].num_p1];
int new_num_p2 = oldNewPlaneMapping[edges[i].num_p2];
if (usefulness == 2) // obie płaszczyzny istnieją, super.
{
//PolyhedronEdge(uint _num_v1, uint _num_v2, uint _num_p1, uint _num_p2)
//.........这里部分代码省略.........
示例2: reserve
/***********************************************************************//**
* @brief Reserves space for parameters in container
*
* @param[in] num Number of parameters.
*
* Reserves space for @p num parameters in the container.
***************************************************************************/
inline
void GOptimizerPars::reserve(const int& num)
{
m_pars.reserve(num);
return;
}
示例3: AppendArray
void AppendArray(std::vector<T> &vec, T* arr, unsigned int size) {
vec.reserve(vec.size() + size);
for (unsigned int i = 0; i < size; i++)
vec.push_back(arr[i]);
}
示例4: p
void
PlotterAdapter3d::project3dNoCopy( std::vector<MC2Point>::iterator begin,
std::vector<MC2Point>::iterator end,
std::vector<MC2Point>& res,
int scalefactor )
{
// Do the needful.
#ifdef __unix__
#undef mc2dbg
//#define mc2dbg cout
#define mc2dbg mc2dbg8
#endif
res.clear();
res.reserve( std::distance( begin, end ) );
checkScreenAndUpdateMembers( scalefactor );
m_clippedPoints.clear();
m_clippedPoints.insert( m_clippedPoints.end(), begin, end );
m_clipUtil.clipPolyToBBoxFast( m_clipBox, m_clippedPoints );
begin = m_clippedPoints.begin();
end = m_clippedPoints.end();
mc2dbg << "M_Height: " << m_height << " m_width: " << m_width << endl;
mc2dbg << "3D: tmppoly = [];" << endl;
for (std::vector<MC2Point>::const_iterator it = begin; it != end; ++it ) {
int intorigx = it->getX();
int intorigy = it->getY();
int intx = -m_intPa*intorigx + m_intPa_times_m_Vd;
int inty = m_intPb_times_m_Vf*intorigy + m_intPb_times_m_Vh;
int intw = -m_intVj*intorigy -m_intVl;
// if ( fabs(x) >= 1 || fabs(y) >= 1 || fabs(z) >= 1 ) {
// mc2dbg << "Outside [-1,1]^3 : x " << x << ",y " << y << ",z " << z << endl;
// }
// int intxw = intwidth*(-intx/intw+1)/2;
// int intyw = inthorizHeight + (intheight - inthorizHeight)*(-inty/intw+2)/2;
int nominatorX = (m_intWidth*intx);
int denominatorX = intw*2;
int tmpIntxw = nominatorX / denominatorX;
if ((nominatorX % denominatorX) >= (denominatorX/2)) {
++ tmpIntxw;
}
int intxw = int(-tmpIntxw + m_intWidth/2);
// Old
// int intxwold = int(-(m_intWidth*intx)/intw/2 + m_intWidth/2);
int nominatorY = ((m_intHeight - m_intHorizHeight)*(inty));
int denominatorY = intw*2;
int tmpIntyw = (nominatorY / denominatorY);
if ((nominatorY % denominatorY) >= (denominatorY/2)) {
++ tmpIntyw;
}
int intyw = int(m_intHorizHeight
-tmpIntyw + (m_intHeight - m_intHorizHeight));
// Old version.
// int intywold = int(m_intHorizHeight +
// ((m_intHeight - m_intHorizHeight)*(-inty))/intw/2 + (m_intHeight - m_intHorizHeight));
#if 0
// if ( rint(xw) != intxw || rint(yw) != intyw) {
cout << "xw = " << xw << ", rint(xw) = " << rint(xw) << ", intxw = " << intxw << ", intxwold = " << intxwold
<< ", yw = " << yw << ", rint(yw) = " << rint(yw) << ", intyw = " << intyw << ", intywold = " << intywold << endl;
if ( w < 0 ) {
mc2dbg << "w " << w << endl;
}
// }
#endif
MC2Point p( intxw, intyw );
// MC2Point p( static_cast<int>(rint(xw)), static_cast<int>(rint(yw)) );
mc2dbg << "orig: " << *it << ", trans: " << p << endl;
// mc2dbg << "3D: " << "tmppoly = [ tmppoly " << p.getX() << " " << p.getY() << " " << (z+1)/2 << " ];" << endl;
res.push_back( p );
}
mc2dbg << "3D: newpolys = append( newpolys, tmppoly );" << endl;
//.........这里部分代码省略.........
示例5: if
//.........这里部分代码省略.........
("dpx:SequenceLength", 0xFFFFFFFF));
m_dpx.header.SetHeldCount (m_spec.get_int_attribute
("dpx:HeldCount", 0xFFFFFFFF));
m_dpx.header.SetFrameRate (m_spec.get_float_attribute
("dpx:FrameRate", std::numeric_limits<float>::quiet_NaN()));
m_dpx.header.SetShutterAngle (m_spec.get_float_attribute
("dpx:ShutterAngle", std::numeric_limits<float>::quiet_NaN()));
// FIXME: should we write the input version through or always default to 2.0?
/*tmpstr = m_spec.get_string_attribute ("dpx:Version", "");
if (tmpstr.size () > 0)
m_dpx.header.SetVersion (tmpstr.c_str ());*/
tmpstr = m_spec.get_string_attribute ("dpx:Format", "");
if (tmpstr.size () > 0)
m_dpx.header.SetFormat (tmpstr.c_str ());
tmpstr = m_spec.get_string_attribute ("dpx:FrameId", "");
if (tmpstr.size () > 0)
m_dpx.header.SetFrameId (tmpstr.c_str ());
tmpstr = m_spec.get_string_attribute ("dpx:SlateInfo", "");
if (tmpstr.size () > 0)
m_dpx.header.SetSlateInfo (tmpstr.c_str ());
tmpstr = m_spec.get_string_attribute ("dpx:SourceImageFileName", "");
if (tmpstr.size () > 0)
m_dpx.header.SetSourceImageFileName (tmpstr.c_str ());
tmpstr = m_spec.get_string_attribute ("dpx:InputDevice", "");
if (tmpstr.size () > 0)
m_dpx.header.SetInputDevice (tmpstr.c_str ());
tmpstr = m_spec.get_string_attribute ("dpx:InputDeviceSerialNumber", "");
if (tmpstr.size () > 0)
m_dpx.header.SetInputDeviceSerialNumber (tmpstr.c_str ());
m_dpx.header.SetInterlace (m_spec.get_int_attribute ("dpx:Interlace", 0xFF));
m_dpx.header.SetFieldNumber (m_spec.get_int_attribute ("dpx:FieldNumber", 0xFF));
m_dpx.header.SetHorizontalSampleRate (m_spec.get_float_attribute
("dpx:HorizontalSampleRate", std::numeric_limits<float>::quiet_NaN()));
m_dpx.header.SetVerticalSampleRate (m_spec.get_float_attribute
("dpx:VerticalSampleRate", std::numeric_limits<float>::quiet_NaN()));
m_dpx.header.SetTemporalFrameRate (m_spec.get_float_attribute
("dpx:TemporalFrameRate", std::numeric_limits<float>::quiet_NaN()));
m_dpx.header.SetTimeOffset (m_spec.get_float_attribute
("dpx:TimeOffset", std::numeric_limits<float>::quiet_NaN()));
m_dpx.header.SetBlackLevel (m_spec.get_float_attribute
("dpx:BlackLevel", std::numeric_limits<float>::quiet_NaN()));
m_dpx.header.SetBlackGain (m_spec.get_float_attribute
("dpx:BlackGain", std::numeric_limits<float>::quiet_NaN()));
m_dpx.header.SetBreakPoint (m_spec.get_float_attribute
("dpx:BreakPoint", std::numeric_limits<float>::quiet_NaN()));
m_dpx.header.SetWhiteLevel (m_spec.get_float_attribute
("dpx:WhiteLevel", std::numeric_limits<float>::quiet_NaN()));
m_dpx.header.SetIntegrationTimes (m_spec.get_float_attribute
("dpx:IntegrationTimes", std::numeric_limits<float>::quiet_NaN()));
float aspect = m_spec.get_float_attribute ("PixelAspectRatio", 1.0f);
int aspect_num, aspect_den;
float_to_rational (aspect, aspect_num, aspect_den);
m_dpx.header.SetAspectRatio (0, aspect_num);
m_dpx.header.SetAspectRatio (1, aspect_den);
tmpstr = m_spec.get_string_attribute ("dpx:TimeCode", "");
int tmpint = m_spec.get_int_attribute ("dpx:TimeCode", ~0);
if (tmpstr.size () > 0)
m_dpx.header.SetTimeCode (tmpstr.c_str ());
else if (tmpint != ~0)
m_dpx.header.timeCode = tmpint;
m_dpx.header.userBits = m_spec.get_int_attribute ("dpx:UserBits", ~0);
tmpstr = m_spec.get_string_attribute ("dpx:SourceDateTime", "");
if (tmpstr.size () >= 19) {
// libdpx's date/time format is pretty close to OIIO's (libdpx uses
// %Y:%m:%d:%H:%M:%S%Z)
// NOTE: the following code relies on the DateTime attribute being properly
// formatted!
// assume UTC for simplicity's sake, fix it if someone complains
tmpstr[10] = ':';
tmpstr.replace (19, -1, "Z");
m_dpx.header.SetSourceTimeDate (tmpstr.c_str ());
}
// commit!
if (!m_dpx.WriteHeader ()) {
error ("Failed to write DPX header");
return false;
}
// user data
ImageIOParameter *user = m_spec.find_attribute ("dpx:UserData");
if (user && user->datasize () > 0) {
if (user->datasize () > 1024 * 1024) {
error ("User data block size exceeds 1 MB");
return false;
}
// FIXME: write the missing libdpx code
/*m_dpx.SetUserData (user->datasize ());
if (!m_dpx.WriteUserData ((void *)user->data ())) {
error ("Failed to write user data");
return false;
}*/
}
// reserve space for the image data buffer
m_buf.reserve (m_bytes * m_spec.height);
return true;
}
示例6: GetTString
bool GetFileString::GetTString(std::vector<T>& From, std::vector<T>& To, bool bBigEndian)
{
typedef eol<T> eol;
bool ExitCode = true;
T* ReadBufPtr = ReadPos < ReadSize ? From.data() + ReadPos / sizeof(T) : nullptr;
To.clear();
// Обработка ситуации, когда у нас пришёл двойной \r\r, а потом не было \n.
// В этом случаем считаем \r\r двумя MAC окончаниями строк.
if (bCrCr)
{
To.emplace_back(T(eol::cr));
bCrCr = false;
}
else
{
EolType Eol = FEOL_NONE;
for (;;)
{
if (ReadPos >= ReadSize)
{
if (!(SrcFile.Read(From.data(), ReadBufCount*sizeof(T), ReadSize) && ReadSize))
{
if (To.empty())
{
ExitCode = false;
}
break;
}
if (bBigEndian && sizeof(T) != 1)
{
_swab(reinterpret_cast<char*>(From.data()), reinterpret_cast<char*>(From.data()), static_cast<int>(ReadSize));
}
ReadPos = 0;
ReadBufPtr = From.data();
}
if (Eol == FEOL_NONE)
{
// UNIX
if (*ReadBufPtr == eol::lf)
{
Eol = FEOL_UNIX;
}
// MAC / Windows? / Notepad?
else if (*ReadBufPtr == eol::cr)
{
Eol = FEOL_MAC;
}
}
else if (Eol == FEOL_MAC)
{
// Windows
if (*ReadBufPtr == eol::lf)
{
Eol = FEOL_WINDOWS;
}
// Notepad?
else if (*ReadBufPtr == eol::cr)
{
Eol = FEOL_MAC2;
}
else
{
break;
}
}
else if (Eol == FEOL_WINDOWS || Eol == FEOL_UNIX)
{
break;
}
else if (Eol == FEOL_MAC2)
{
// Notepad
if (*ReadBufPtr == eol::lf)
{
Eol = FEOL_NOTEPAD;
}
else
{
// Пришёл \r\r, а \n не пришёл, поэтому считаем \r\r двумя MAC окончаниями строк
To.pop_back();
bCrCr = true;
break;
}
}
else
{
break;
}
ReadPos += sizeof(T);
if (To.size() == To.capacity())
To.reserve(To.size() * 2);
To.emplace_back(*ReadBufPtr);
//.........这里部分代码省略.........
示例7: deform
MStatus mapBlendShape::deform(MDataBlock& data,
MItGeometry& itGeo,
const MMatrix& localToWorldMatrix,
unsigned int geomIndex)
{
MStatus status;
// get the blendMesh
MDataHandle hBlendMesh = data.inputValue( aBlendMesh, &status );
CHECK_MSTATUS_AND_RETURN_IT( status );
MObject oBlendMesh = hBlendMesh.asMesh();
if (oBlendMesh.isNull())
{
return MS::kSuccess;
}
MFnMesh fnMesh( oBlendMesh, &status );
CHECK_MSTATUS_AND_RETURN_IT( status );
MPointArray blendPoints;
fnMesh.getPoints( blendPoints );
// get the dirty flags for the input and blendMap
bool inputGeomClean = data.isClean(inputGeom, &status);
bool blendMapClean = data.isClean(aBlendMap, &status);
if (!blendMapClean) {
lumValues.reserve(itGeo.count());
}
MDoubleArray uCoords, vCoords;
MVectorArray resultColors;
MDoubleArray resultAlphas;
uCoords.setLength(1);
vCoords.setLength(1);
bool hasTextureNode;
bool useBlendMap = data.inputValue(aUseBlendMap).asBool();
float blendMapMultiplier = data.inputValue(aBlendMapMultiplier).asFloat();
if (blendMapMultiplier<=0.0) {
useBlendMap = false;
}
if (useBlendMap) {
hasTextureNode = MDynamicsUtil::hasValidDynamics2dTexture(thisMObject(), aBlendMap);
}
float env = data.inputValue(envelope).asFloat();
MPoint point;
float2 uvPoint;
float w, lum;
for ( ; !itGeo.isDone(); itGeo.next() )
{
lum = 1.0;
if (useBlendMap) {
if (!blendMapClean) {
fnMesh.getUVAtPoint(blendPoints[itGeo.index()], uvPoint);
if (hasTextureNode) {
uCoords[0] = uvPoint[0];
vCoords[0] = uvPoint[1];
MDynamicsUtil::evalDynamics2dTexture(thisMObject(), aBlendMap, uCoords, vCoords, &resultColors, &resultAlphas);
lum = float(resultColors[0][0]);
}
lumValues[itGeo.index()] = lum;
} else {
lum = lumValues[itGeo.index()];
}
}
point = itGeo.position();
w = weightValue( data, geomIndex, itGeo.index() );
point += (blendPoints[itGeo.index()] - point) * env * w * lum * blendMapMultiplier;
itGeo.setPosition( point );
}
return MS::kSuccess;
}
示例8: main
int main(int argc, char *argv[]) {
#ifdef COPP_MACRO_SYS_POSIX
puts("###################### context coroutine (stack using default allocator[mmap]) ###################");
#elif defined(COPP_MACRO_SYS_WIN)
puts("###################### context coroutine (stack using default allocator[VirtualAlloc]) ###################");
#else
puts("###################### context coroutine (stack using default allocator ###################");
#endif
printf("########## Cmd:");
for (int i = 0; i < argc; ++i) {
printf(" %s", argv[i]);
}
puts("");
if (argc > 1) {
max_task_number = atoi(argv[1]);
}
if (argc > 2) {
switch_count = atoi(argv[2]);
}
size_t stack_size = 16 * 1024;
if (argc > 3) {
stack_size = atoi(argv[3]) * 1024;
}
time_t begin_time = time(NULL);
clock_t begin_clock = clock();
// create coroutines
task_arr.reserve(static_cast<size_t>(max_task_number));
while (task_arr.size() < static_cast<size_t>(max_task_number)) {
my_task_t::ptr_t new_task = my_task_t::create(my_task_action, stack_size);
if (!new_task) {
fprintf(stderr, "create coroutine task failed, real size is %d.\n", static_cast<int>(task_arr.size()));
fprintf(stderr, "maybe sysconf [vm.max_map_count] extended.\n");
max_task_number = static_cast<int>(task_arr.size());
break;
}
task_arr.push_back(new_task);
}
time_t end_time = time(NULL);
clock_t end_clock = clock();
printf("create %d task, cost time: %d s, clock time: %d ms, avg: %lld ns\n", max_task_number, static_cast<int>(end_time - begin_time),
CALC_MS_CLOCK(end_clock - begin_clock), CALC_NS_AVG_CLOCK(end_clock - begin_clock, max_task_number));
begin_time = end_time;
begin_clock = end_clock;
// start a task
for (int i = 0; i < max_task_number; ++i) {
task_arr[i]->start();
}
// yield & resume from runner
bool continue_flag = true;
long long real_switch_times = static_cast<long long>(0);
while (continue_flag) {
continue_flag = false;
for (int i = 0; i < max_task_number; ++i) {
if (false == task_arr[i]->is_completed()) {
continue_flag = true;
++real_switch_times;
task_arr[i]->resume();
}
}
}
end_time = time(NULL);
end_clock = clock();
printf("switch %d tasks %lld times, cost time: %d s, clock time: %d ms, avg: %lld ns\n", max_task_number, real_switch_times,
static_cast<int>(end_time - begin_time), CALC_MS_CLOCK(end_clock - begin_clock),
CALC_NS_AVG_CLOCK(end_clock - begin_clock, real_switch_times));
begin_time = end_time;
begin_clock = end_clock;
task_arr.clear();
end_time = time(NULL);
end_clock = clock();
printf("remove %d tasks, cost time: %d s, clock time: %d ms, avg: %lld ns\n", max_task_number, static_cast<int>(end_time - begin_time),
CALC_MS_CLOCK(end_clock - begin_clock), CALC_NS_AVG_CLOCK(end_clock - begin_clock, max_task_number));
return 0;
}
示例9: AggregatorImpl
AggregatorImpl() {
m_trie.reserve(4096);
}
示例10: compute_gForce
void compute_gForce(const double theta, Particle::Vector &ptcl, bool verbose = true, bool dump_morton = false)
{
using namespace std;
// Setup timer
using _time = chrono::system_clock;
// Build octree
const int n_bodies = ptcl.size();
static Octree::Body::Vector octBodies;
octBodies.clear();
octBodies.reserve(n_bodies);
const auto t_build_tree_beg = _time::now();
if (verbose)
fprintf(stderr, " -- Build octree -- \n");
vec3 rmin(+HUGE);
vec3 rmax(-HUGE);
for (int i = 0; i < n_bodies; i++)
{
octBodies.push_back(Octree::Body(ptcl[i],i));
rmin = mineach(rmin, ptcl[i].pos);
rmax = maxeach(rmax, ptcl[i].pos);
}
const vec3 centre = (rmax + rmin)*0.5;
const vec3 vsize = rmax - rmin;
const real size = __max(__max(vsize.x, vsize.y), vsize.z);
real size2 = 1.0;
while (size2 > size) size2 *= 0.5;
while (size2 < size) size2 *= 2.0;
const int n_nodes = n_bodies;
Octree tree(centre, size2, n_nodes, theta);
for (int i = 0; i < n_bodies; i++)
{
tree.insert(octBodies[i]);
}
if (verbose)
fprintf(stderr, "ncell= %d nnode= %d nleaf= %d n_nodes= %d depth= %d np= %d\n",
tree.get_ncell(), tree.get_nnode(), tree.get_nleaf(), n_nodes, tree.get_depth(), tree.get_np());
const auto t_build_tree_end = _time::now();
const auto t_boundaries_beg = _time::now();
tree.computeBoundaries();
if (verbose)
{
const boundary root_innerBnd = tree.root_innerBoundary();
fprintf(stderr, " rootBnd_inner= %g %g %g size= %g %g %g \n",
root_innerBnd.center().x,
root_innerBnd.center().y,
root_innerBnd.center().z,
root_innerBnd.hlen().x,
root_innerBnd.hlen().y,
root_innerBnd.hlen().z);
const boundary root_outerBnd = tree.root_outerBoundary();
fprintf(stderr, " rootBnd_outer= %g %g %g size= %g %g %g \n",
root_outerBnd.center().x,
root_outerBnd.center().y,
root_outerBnd.center().z,
root_outerBnd.hlen().x,
root_outerBnd.hlen().y,
root_outerBnd.hlen().z);
fprintf(stderr, "rootCentre:= %g %g %g rootSize= %g \n",
tree.get_rootCentre().x,
tree.get_rootCentre().y,
tree.get_rootCentre().z,
tree.get_rootSize());
}
const auto t_boundaries_end = _time::now();
const auto t_sanity_check_beg = _time::now();
assert(tree.sanity_check() == n_bodies);
const auto t_sanity_check_end = _time::now();
const auto t_build_leaf_list_beg = _time::now();
tree.buildLeafList();
const auto t_build_leaf_list_end = _time::now();
const auto t_build_group_list_beg = _time::now();
static octGroup::Vector groupList;
groupList.clear();
groupList.reserve(tree.nLeaf());
tree.buildGroupList</* SORT */ 0 ? true : false>(groupList);
const int ngroup = groupList.size();
const auto t_build_group_list_end = _time::now();
if (verbose)
fprintf(stderr, " Computing multipole \n");
const auto t_compute_multipole_beg = _time::now();
const Octree::dMultipole rootM = tree.computeMultipole(ptcl);
const auto t_compute_multipole_end = _time::now();
if (verbose)
//.........这里部分代码省略.........
示例11: Cell
Cell() { entries.reserve(16); }
示例12: init_exact_species
void init_exact_species()
{
_H2_species_id = 0;
_N2_species_id = 47;
_HCNO_species_id = 43;
_species_exact.reserve(53);
_species_exact.push_back("H2");
_species_exact.push_back("H");
_species_exact.push_back("O");
_species_exact.push_back("O2");
_species_exact.push_back("OH");
_species_exact.push_back("H2O");
_species_exact.push_back("HO2");
_species_exact.push_back("H2O2");
_species_exact.push_back("C");
_species_exact.push_back("CH");
_species_exact.push_back("CH2");
_species_exact.push_back("CH2(S)");
_species_exact.push_back("CH3");
_species_exact.push_back("CH4");
_species_exact.push_back("CO");
_species_exact.push_back("CO2");
_species_exact.push_back("HCO");
_species_exact.push_back("CH2O");
_species_exact.push_back("CH2OH");
_species_exact.push_back("CH3O");
_species_exact.push_back("CH3OH");
_species_exact.push_back("C2H");
_species_exact.push_back("C2H2");
_species_exact.push_back("C2H3");
_species_exact.push_back("C2H4");
_species_exact.push_back("C2H5");
_species_exact.push_back("C2H6");
_species_exact.push_back("HCCO");
_species_exact.push_back("CH2CO");
_species_exact.push_back("HCCOH");
_species_exact.push_back("N");
_species_exact.push_back("NH");
_species_exact.push_back("NH2");
_species_exact.push_back("NH3");
_species_exact.push_back("NNH");
_species_exact.push_back("NO");
_species_exact.push_back("NO2");
_species_exact.push_back("N2O");
_species_exact.push_back("HNO");
_species_exact.push_back("CN");
_species_exact.push_back("HCN");
_species_exact.push_back("H2CN");
_species_exact.push_back("HCNN");
_species_exact.push_back("HCNO");
_species_exact.push_back("HOCN");
_species_exact.push_back("HNCO");
_species_exact.push_back("NCO");
_species_exact.push_back("N2");
_species_exact.push_back("AR");
_species_exact.push_back("C3H7");
_species_exact.push_back("C3H8");
_species_exact.push_back("CH2CHO");
_species_exact.push_back("CH3CHO");
}
示例13: add
void add( const entry& p )
{
if( points.size() == points.capacity() ) { points.reserve( 2048 ); } // quick and dirty
points.push_back( p );
}
示例14: initCompute
template <typename PointT> void
pcl::MinCutSegmentation<PointT>::extract (std::vector <pcl::PointIndices>& clusters)
{
clusters.clear ();
bool segmentation_is_possible = initCompute ();
if ( !segmentation_is_possible )
{
deinitCompute ();
return;
}
if ( graph_is_valid_ && unary_potentials_are_valid_ && binary_potentials_are_valid_ )
{
clusters.reserve (clusters_.size ());
std::copy (clusters_.begin (), clusters_.end (), std::back_inserter (clusters));
deinitCompute ();
return;
}
clusters_.clear ();
bool success = true;
if ( !graph_is_valid_ )
{
success = buildGraph ();
if (success == false)
{
deinitCompute ();
return;
}
graph_is_valid_ = true;
unary_potentials_are_valid_ = true;
binary_potentials_are_valid_ = true;
}
if ( !unary_potentials_are_valid_ )
{
success = recalculateUnaryPotentials ();
if (success == false)
{
deinitCompute ();
return;
}
unary_potentials_are_valid_ = true;
}
if ( !binary_potentials_are_valid_ )
{
success = recalculateBinaryPotentials ();
if (success == false)
{
deinitCompute ();
return;
}
binary_potentials_are_valid_ = true;
}
//IndexMap index_map = boost::get (boost::vertex_index, *graph_);
ResidualCapacityMap residual_capacity = boost::get (boost::edge_residual_capacity, *graph_);
max_flow_ = boost::boykov_kolmogorov_max_flow (*graph_, source_, sink_);
assembleLabels (residual_capacity);
deinitCompute ();
}
示例15: operator
void CompleteLinkage::operator()(DistanceMatrix<float> & original_distance, std::vector<BinaryTreeNode> & cluster_tree, const float threshold /*=1*/) const
{
// attention: clustering process is done by clustering the indices
// pointing to elements in inputvector and distances in inputmatrix
// input MUST have >= 2 elements!
if (original_distance.dimensionsize() < 2)
{
throw ClusterFunctor::InsufficientInput(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Distance matrix to start from only contains one element");
}
std::vector<std::set<Size> > clusters(original_distance.dimensionsize());
for (Size i = 0; i < original_distance.dimensionsize(); ++i)
{
clusters[i].insert(i);
}
cluster_tree.clear();
cluster_tree.reserve(original_distance.dimensionsize() - 1);
// Initial minimum-distance pair
original_distance.updateMinElement();
std::pair<Size, Size> min = original_distance.getMinElementCoordinates();
Size overall_cluster_steps(original_distance.dimensionsize());
startProgress(0, original_distance.dimensionsize(), "clustering data");
while (original_distance(min.first, min.second) < threshold)
{
//grow the tree
cluster_tree.push_back(BinaryTreeNode(*(clusters[min.second].begin()), *(clusters[min.first].begin()), original_distance(min.first, min.second)));
if (cluster_tree.back().left_child > cluster_tree.back().right_child)
{
std::swap(cluster_tree.back().left_child, cluster_tree.back().right_child);
}
if (original_distance.dimensionsize() > 2)
{
//pick minimum-distance pair i,j and merge them
//pushback elements of second to first (and then erase second)
clusters[min.second].insert(clusters[min.first].begin(), clusters[min.first].end());
// erase first one
clusters.erase(clusters.begin() + min.first);
//update original_distance matrix
//complete linkage: new distance between clusters is the minimum distance between elements of each cluster
//lance-williams update for d((i,j),k): 0.5* d(i,k) + 0.5* d(j,k) + 0.5* |d(i,k)-d(j,k)|
for (Size k = 0; k < min.second; ++k)
{
float dik = original_distance.getValue(min.first, k);
float djk = original_distance.getValue(min.second, k);
original_distance.setValueQuick(min.second, k, (0.5f * dik + 0.5f * djk + 0.5f * std::fabs(dik - djk)));
}
for (Size k = min.second + 1; k < original_distance.dimensionsize(); ++k)
{
float dik = original_distance.getValue(min.first, k);
float djk = original_distance.getValue(min.second, k);
original_distance.setValueQuick(k, min.second, (0.5f * dik + 0.5f * djk + 0.5f * std::fabs(dik - djk)));
}
//reduce
original_distance.reduce(min.first);
//update minimum-distance pair
original_distance.updateMinElement();
//get new min-pair
min = original_distance.getMinElementCoordinates();
}
else
{
break;
}
setProgress(overall_cluster_steps - original_distance.dimensionsize());
//repeat until only two cluster remains or threshold exceeded, last step skips matrix operations
}
//fill tree with dummy nodes
Size sad(*clusters.front().begin());
for (Size i = 1; i < clusters.size() && (cluster_tree.size() < cluster_tree.capacity()); ++i)
{
cluster_tree.push_back(BinaryTreeNode(sad, *clusters[i].begin(), -1.0));
}
//~ while(cluster_tree.size() < cluster_tree.capacity())
//~ {
//~ cluster_tree.push_back(BinaryTreeNode(0,1,-1.0));
//~ }
endProgress();
}