本文整理汇总了C++中r2函数的典型用法代码示例。如果您正苦于以下问题:C++ r2函数的具体用法?C++ r2怎么用?C++ r2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了r2函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: run_main
int
run_main (int, ACE_TCHAR *[])
{
ACE_START_TEST (ACE_TEXT ("Bound_Ptr_Test"));
// =========================================================================
// The following test uses the ACE_Strong_Bound_Ptr in a single
// thread of control, hence we use the ACE_Null_Mutex
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) performing synchronous test...\n")));
Parent *parent1 = 0;
ACE_NEW_RETURN (parent1,
Parent,
-1);
ACE_Weak_Bound_Ptr<Parent, ACE_Null_Mutex> p8;
{
// Must get the pointer from the parent object's weak_self_ member.
ACE_Strong_Bound_Ptr<Parent, ACE_Null_Mutex> p(parent1->weak_self_);
ACE_Strong_Bound_Ptr<Parent, ACE_Null_Mutex> p1(p);
ACE_Strong_Bound_Ptr<Parent, ACE_Null_Mutex> p2(p);
ACE_Weak_Bound_Ptr<Parent, ACE_Null_Mutex> p3(p);
ACE_Strong_Bound_Ptr<Parent, ACE_Null_Mutex> p4(p);
ACE_Strong_Bound_Ptr<Parent, ACE_Null_Mutex> p5 = p2;
ACE_Strong_Bound_Ptr<Parent, ACE_Null_Mutex> p6 = p3;
ACE_Weak_Bound_Ptr<Parent, ACE_Null_Mutex> p7(p1);
p8 = p2;
p->child_->do_something ();
}
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) Parent instance count is %d, expecting 0\n"),
Parent::instance_count_));
if (Parent::instance_count_ != 0)
{
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("(%t) parent instance count not 0...\n")),
-1);
}
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) Child instance count is %d, expecting 0\n"),
Child::instance_count_));
if (Child::instance_count_ != 0)
{
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("(%t) child instance count not 0...\n")),
-1);
}
// Weak pointer should now be set to null.
if(!p8.null ())
{
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("(%t) p8 not nill...\n")),
-1);
}
Printer *printer1 = 0;
ACE_NEW_RETURN (printer1,
Printer ("I am printer 1"),
-1);
ACE_Weak_Bound_Ptr<Printer, ACE_Null_Mutex> r9;
{
ACE_Strong_Bound_Ptr<Printer, ACE_Null_Mutex> r(printer1);
ACE_Strong_Bound_Ptr<Printer, ACE_Null_Mutex> r1(r);
ACE_Strong_Bound_Ptr<Printer, ACE_Null_Mutex> r2(r);
ACE_Strong_Bound_Ptr<Printer, ACE_Null_Mutex> r3(r);
ACE_Strong_Bound_Ptr<Printer, ACE_Null_Mutex> r4(r);
ACE_Strong_Bound_Ptr<Printer, ACE_Null_Mutex> r5 = r2;
ACE_Strong_Bound_Ptr<Printer, ACE_Null_Mutex> r6 = r1;
ACE_Weak_Bound_Ptr<Printer, ACE_Null_Mutex> r7(r1);
ACE_Weak_Bound_Ptr<Printer, ACE_Null_Mutex> r8 = r2;
r9 = r3;
r9->print ();
}
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) Printer instance count is %d, expecting 0\n"),
Printer::instance_count_));
if (Printer::instance_count_ != 0)
{
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("(%t) Printer instance count not 0...\n")),
-1);
}
// Weak pointer should now be set to null.
if (!r9.null ())
{
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("(%t) r9 not nill...\n")),
-1);
}
#if defined (ACE_HAS_THREADS)
// =========================================================================
// The following test uses the ACE_Strong_Bound_Ptr in multiple
// threads of control.
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) performing asynchronous test...\n")));
//.........这里部分代码省略.........
开发者ID:INMarkus,项目名称:ATCD,代码行数:101,代码来源:Bound_Ptr_Test.cpp
示例2: test_main
int
test_main(int,char*[])
{
typedef boost::detail::multi_array::index_range<int,std::size_t> range;
{
// typical range creation and extraction
range r1(-3,5);
BOOST_CHECK(r1.start() == -3);
BOOST_CHECK(r1.finish() == 5);
BOOST_CHECK(r1.stride() == 1);
BOOST_CHECK(!r1.is_degenerate());
BOOST_CHECK(r1.get_start(0) == -3);
BOOST_CHECK(r1.get_finish(100) == 5);
}
{
range r2(-3,5,2);
BOOST_CHECK(r2.start() == -3);
BOOST_CHECK(r2.finish() == 5);
BOOST_CHECK(r2.stride() == 2);
BOOST_CHECK(!r2.is_degenerate());
}
{
// degenerate creation
range r3(5);
BOOST_CHECK(r3.start() == 5);
BOOST_CHECK(r3.finish() == 6);
BOOST_CHECK(r3.stride() == 1);
BOOST_CHECK(r3.is_degenerate());
}
{
// default range creation
range r4;
BOOST_CHECK(r4.get_start(0) == 0);
BOOST_CHECK(r4.get_finish(100) == 100);
BOOST_CHECK(r4.stride() == 1);
}
{
// create a range using the setter methods
range r5 = range().stride(2).start(-3).finish(7);
BOOST_CHECK(r5.start() == -3);
BOOST_CHECK(r5.stride() == 2);
BOOST_CHECK(r5.finish() == 7);
}
// try out all the comparison operators
{
range r6 = -3 <= range().stride(2) < 7;
BOOST_CHECK(r6.start() == -3);
BOOST_CHECK(r6.stride() == 2);
BOOST_CHECK(r6.finish() == 7);
}
{
range r7 = -3 < range() <= 7;
BOOST_CHECK(r7.start() == -2);
BOOST_CHECK(r7.stride() == 1);
BOOST_CHECK(r7.finish() == 8);
}
// arithmetic operators
{
range r8 = range(0,5) + 2;
BOOST_CHECK(r8.start() == 2);
BOOST_CHECK(r8.stride() == 1);
BOOST_CHECK(r8.finish() == 7);
}
{
range r9 = range(0,5) - 2;
BOOST_CHECK(r9.start() == -2);
BOOST_CHECK(r9.stride() == 1);
BOOST_CHECK(r9.finish() == 3);
}
#ifdef __SYMBIAN32__
if(boost::minimal_test::errors_counter() != 0)
assert_failed = true;
testResultXml("range1");
close_log_file();
#endif
return boost::exit_success;
}
开发者ID:cdaffara,项目名称:symbiandump-os2,代码行数:87,代码来源:range1.cpp
示例3: main
//.........这里部分代码省略.........
r.ReadRequest((int)pow(2,ADDR_COL_WIDTH));
do {
r.NextClockCycle();
} while (r.read_ready() == false);
assert (r.cycle_count() - start_cycle == TRCD + TCL + TRP+1); //off by 1 to start pipeline to clock into fifo
start_cycle = r.cycle_count();
do {
r.NextClockCycle();
} while (r.read_ready() == false);
assert (r.cycle_count() - start_cycle == Ram<int>::BURST_LENGTH/2); //check for burst rate limiting
start_cycle = r.cycle_count();
do {
r.NextClockCycle();
} while (r.read_ready() == false);
assert (r.cycle_count() - start_cycle == Ram<int>::BURST_LENGTH/2);
start_cycle = r.cycle_count();
do {
r.NextClockCycle();
} while (r.read_ready() == false);
uint64_t expected = Ram<uint64_t>::BURST_LENGTH/2;
uint64_t expected1 = TRCD + TCL + TRP - Ram<uint64_t>::BURST_LENGTH/2*2;
if ( expected1 > Ram<uint64_t>::BURST_LENGTH/2) {
expected = expected1;
}
assert (r.cycle_count() - start_cycle == expected);
// halving system clock frequency
Ram<uint64_t> r2(ADDR_ROW_WIDTH, ADDR_COL_WIDTH, ADDR_BANK_WIDTH,
SYSTEM_CLK_FREQ/2, MEM_CLK_FREQ,
TRCD, TCL, TRP);
// Check initial states
assert(r2.read_ready() == false);
// Read after Write Test
for (unsigned int i = 0; i < pow(2, ADDRESS_WIDTH); i++) {
r2.WriteRequest(i, i);
r2.NextClockCycle();
}
for (unsigned int i = 0; i < (TRCD+TCL+TRP)*pow(2, ADDRESS_WIDTH)*10; i++) {
r2.NextClockCycle();
}
start_cycle = r2.cycle_count();
assert(r2.read_ready() == false);
for (int col = 0; col < pow(2, ADDR_COL_WIDTH); col++) {
for (int row = 0; row < pow(2, ADDR_ROW_WIDTH); row++) {
for (int bank = 0; bank < pow(2, ADDR_BANK_WIDTH); bank++) {
uint64_t address = (bank << (ADDR_ROW_WIDTH+ADDR_COL_WIDTH)) | (row << (ADDR_COL_WIDTH)) | col;
r2.ReadRequest(address);
do {
r2.NextClockCycle();
} while (r2.read_ready() == false);
assert(r2.read_data() == address);
}
}
}
//same row, same bank
r2.Reset();
start_cycle = r2.cycle_count();
开发者ID:sdamico,项目名称:cs316,代码行数:67,代码来源:ram_test.cpp
示例4: calibrate
void calibrate(const std::vector<TiePoint>& tiePoints,const int gridSize[2],const double tileSize[2],const unsigned int depthFrameSize[2],const unsigned int colorFrameSize[2])
{
/* Initialize the depth camera's intrinsic parameter matrix: */
Math::Matrix depthV(6,6,0.0);
/* Process all tie points: */
for(std::vector<TiePoint>::const_iterator tpIt=tiePoints.begin(); tpIt!=tiePoints.end(); ++tpIt)
{
/* Enter the tie point's depth homography into the intrinsic parameter matrix: */
Homography::Matrix hm(1.0);
hm(0,2)=double(depthFrameSize[0]);
hm*=tpIt->depthHom.getMatrix();
Homography::Matrix scale(1.0);
scale(0,0)=1.0/tileSize[0];
scale(1,1)=1.0/tileSize[1];
hm*=scale;
double row[3][6];
static const int is[3]= {0,0,1};
static const int js[3]= {1,0,1};
for(int r=0; r<3; ++r)
{
int i=is[r];
int j=js[r];
row[r][0]=hm(0,i)*hm(0,j);
row[r][1]=hm(0,i)*hm(1,j)+hm(1,i)*hm(0,j);
row[r][2]=hm(0,i)*hm(2,j)+hm(2,i)*hm(0,j);
row[r][3]=hm(1,i)*hm(1,j);
row[r][4]=hm(1,i)*hm(2,j)+hm(2,i)*hm(1,j);
row[r][5]=hm(2,i)*hm(2,j);
}
for(int i=0; i<6; ++i)
row[1][i]-=row[2][i];
for(int r=0; r<2; ++r)
{
for(unsigned int i=0; i<6; ++i)
for(unsigned int j=0; j<6; ++j)
depthV(i,j)+=row[r][i]*row[r][j];
}
}
/* Find the intrinsic parameter linear system's smallest eigenvalue: */
std::pair<Math::Matrix,Math::Matrix> depthQe=depthV.jacobiIteration();
unsigned int minEIndex=0;
double minE=Math::abs(depthQe.second(0));
for(unsigned int i=1; i<6; ++i)
{
if(minE>Math::abs(depthQe.second(i)))
{
minEIndex=i;
minE=Math::abs(depthQe.second(i));
}
}
std::cout<<"Smallest eigenvalue of v = "<<depthQe.second(minEIndex)<<std::endl;
/* Calculate the intrinsic parameters: */
Math::Matrix b=depthQe.first.getColumn(minEIndex);
std::cout<<b(0)<<", "<<b(1)<<", "<<b(2)<<", "<<b(3)<<", "<<b(4)<<", "<<b(5)<<std::endl;
double v0=(b(1)*b(2)-b(0)*b(4))/(b(0)*b(3)-Math::sqr(b(1)));
double lambda=b(5)-(Math::sqr(b(2))+v0*(b(1)*b(2)-b(0)*b(4)))/b(0);
double alpha=Math::sqrt(lambda/b(0));
double beta=Math::sqrt(lambda*b(0)/(b(0)*b(3)-Math::sqr(b(1))));
double gamma=-b(1)*Math::sqr(alpha)*beta/lambda;
double u0=gamma*v0/beta-b(2)*Math::sqr(alpha)/lambda;
std::cout<<"Intrinsic camera parameters:"<<std::endl;
std::cout<<alpha<<" "<<gamma<<" "<<u0<<std::endl;
std::cout<<0.0<<" "<<beta<<" "<<v0<<std::endl;
std::cout<<0.0<<" "<<0.0<<" "<<1.0<<std::endl;
/* Create the intrinsic camera parameter matrix: */
Math::Matrix a(3,3,1.0);
a.set(0,0,alpha);
a.set(0,1,gamma);
a.set(0,2,u0);
a.set(1,1,beta);
a.set(1,2,v0);
Math::Matrix aInv=a.inverse();
/* Calculate extrinsic parameters for each tie point to get measurements for the depth formula regression: */
Math::Matrix depthAta(2,2,0.0);
Math::Matrix depthAtb(2,1,0.0);
for(std::vector<TiePoint>::const_iterator tpIt=tiePoints.begin(); tpIt!=tiePoints.end(); ++tpIt)
{
/* Convert the tie point's depth homography to a matrix: */
Homography::Matrix hm(1.0);
hm(0,2)=double(depthFrameSize[0]);
hm*=tpIt->depthHom.getMatrix();
Homography::Matrix scale(1.0);
scale(0,0)=1.0/tileSize[0];
scale(1,1)=1.0/tileSize[1];
hm*=scale;
Math::Matrix h(3,3);
for(unsigned int i=0; i<3; ++i)
for(unsigned int j=0; j<3; ++j)
h(i,j)=hm(i,j);
/* Calculate the extrinsic parameters: */
double lambda=0.5/(aInv*h.getColumn(0)).mag()+0.5/(aInv*h.getColumn(1)).mag();
Math::Matrix r1=lambda*aInv*h.getColumn(0);
Math::Matrix r2=lambda*aInv*h.getColumn(1);
//.........这里部分代码省略.........
开发者ID:urbanlab,项目名称:augmented_sandbox,代码行数:101,代码来源:NewCalibrateCameras.cpp
示例5: ADD_BALL
void MainGame::initBalls() {
// Initializes the grid
_grid = std::make_unique<Grid>(m_screenWidth, m_screenHeight, CELL_SIZE);
#define ADD_BALL(p, ...) \
totalProbability += p; \
possibleBalls.emplace_back(__VA_ARGS__);
// Number of balls to spawn
const int NUM_BALLS = 5000;
// Random engine stuff
std::mt19937 randomEngine((unsigned int)time(nullptr));
std::uniform_real_distribution<float> randX(0.0f, (float)m_screenWidth);
std::uniform_real_distribution<float> randY(0.0f, (float)m_screenHeight);
std::uniform_real_distribution<float> randDir(-1.0f, 1.0f);
// Add all possible balls
std::vector <BallSpawn> possibleBalls;
float totalProbability = 0.0f;
std::uniform_real_distribution<float> r1(2.0f, 6.0f);
std::uniform_int_distribution<int> r2(0, 255);
// Adds the balls using a macro
ADD_BALL(20.0f, Engine::Color(255, 255, 255, 255),
2.0f, 1.0f, 0.1f, 7.0f, totalProbability);
ADD_BALL(10.0f, Engine::Color(0, 0, 255, 255),
3.0f, 2.0f, 0.1f, 3.0f, totalProbability);
ADD_BALL(1.0f, Engine::Color(255, 0, 0, 255),
5.0f, 4.0f, 0.0f, 0.0f, totalProbability);
for (int i = 0; i < 10000; i++){
ADD_BALL(1.0f, Engine::Color(r2(randomEngine), r2(randomEngine), r2(randomEngine), 255), r1(randomEngine), r1(randomEngine), 0.0f, 0.0f, totalProbability);
}
// Random probability for ball spawn
std::uniform_real_distribution<float> spawn(0.0f, totalProbability);
// Small optimization that sets the size of the internal array to prevent
// extra allocations.
m_balls.reserve(NUM_BALLS);
// Set up ball to spawn with default value
BallSpawn* ballToSpawn = &possibleBalls[0];
for (int i = 0; i < NUM_BALLS; i++) {
// Get the ball spawn roll
float spawnVal = spawn(randomEngine);
// Figure out which ball we picked
for (size_t j = 0; j < possibleBalls.size(); j++) {
if (spawnVal <= possibleBalls[j].probability) {
ballToSpawn = &possibleBalls[j];
break;
}
}
// Get random starting position
glm::vec2 pos(randX(randomEngine), randY(randomEngine));
// Hacky way to get a random direction
glm::vec2 direction(randDir(randomEngine), randDir(randomEngine));
if (direction.x != 0.0f || direction.y != 0.0f) { // The chances of direction == 0 are astronomically low
direction = glm::normalize(direction);
} else {
direction = glm::vec2(1.0f, 0.0f); // default direction
}
// Add ball
m_balls.emplace_back(ballToSpawn->radius, ballToSpawn->mass, pos, direction * ballToSpawn->randSpeed(randomEngine),
Engine::ResourceManager::getTexture("Textures/circle.png").id,
ballToSpawn->color);
// Add the ball to the grid.
_grid->addBall(&m_balls.back());
}
}
开发者ID:IAnonymousI,项目名称:BallGame,代码行数:76,代码来源:MainGame.cpp
示例6: basic_example
//! Basic usage (simple creation of tracking pointers and destruction of them vs destruction of their targets)
void basic_example() {
// Create two instances of class C (their lifetime is managed by unique_ptr), name them i1 and i2
std::unique_ptr<C> i1(new C(1));
std::unique_ptr<C> i2(new C(2));
// Create tracking pointer to i1, pass it an "invalidation function" to be called when the instance gets destructed
tracking_ptr<C> r1_1(*i1, [](tracking_ptr<C>& /*dummy*/){std::cout << "! r1_1: i1 invalidated" << std::endl;});
// Use the pointer to work with the pointed-to instance
r1_1->print();
// Create another tracking pointer to i1 (the count of tracking pointers is not limited)
tracking_ptr<C> r1_2(*i1, [](tracking_ptr<C>& /*dummy*/){std::cout << "! r1_2: i1 invalidated" << std::endl;});
// Create a tracking pointer to i2
tracking_ptr<C> r2(*i2, [](tracking_ptr<C>& /*dummy*/){std::cout << "! r2: i2 invalidated" << std::endl;});
// Work with the pointers "directly"...
r1_1->print();
r1_2->print();
r2->print();
// ... get the raw pointer and work with that instead ...
{
C * cp = r2.get();
cp->print();
}
// ... or dereference the pointer to get reference to the instance
(*r2).print();
// Let's kill i1
// While it gets destroyed, it invalidates all tracking pointers pointing at it
std::cout << "killing i1" << std::endl;
i1.reset();
// i1 is now dead, touching invalidated tracking pointers throws
try {
r1_1->print();
} catch (const std::exception & e) {
std::cout << e.what() << std::endl;
}
try {
r1_2->print();
} catch (const std::exception & e) {
std::cout << e.what() << std::endl;
}
// But i2 is still alive, we may still use the tracking pointer to it
r2->print();
std::cout << "(end of scope)" << std::endl;
// Local variables will be destructed in the reverse order of construction:
// ~r2, ~r1_2, ~r1_1, ~i2, ~i1
// Because r2 gets destructed before i2, no invalidation is triggered, only the tracking_ptr gets freed from its tracker (the object it points at)
// Destruction of r1_2 (and r1_1) skips the pointers being freed since the tracker does not exist anymore (i1 is already dead)
// Destruction of i2 does not trigger invalidation of tracking pointer r2, because it has been freed
// Destruction of i1 does nothing since the unique_ptr is already null
}
开发者ID:M-1,项目名称:tracking_ptr,代码行数:65,代码来源:main.cpp
示例7: r2
rgbColor whittedRayTracer::L(const ray& r) const{
ray r2(r);
return _L(r2);
}
开发者ID:HapeMask,项目名称:rt,代码行数:4,代码来源:whitted.cpp
示例8: CoinShallowPackedVectorUnitTest
void
CoinShallowPackedVectorUnitTest()
{
CoinRelFltEq eq;
int i;
// Test default constructor
{
CoinShallowPackedVector r;
assert( r.indices_==NULL );
assert( r.elements_==NULL );
assert( r.nElements_==0 );
}
// Test set and get methods
const int ne = 4;
int inx[ne] = { 1, 3, 4, 7 };
double el[ne] = { 1.2, 3.4, 5.6, 7.8 };
{
CoinShallowPackedVector r;
assert( r.getNumElements()==0 );
// Test setting/getting elements with int* & double* vectors
r.setVector( ne, inx, el );
assert( r.getNumElements()==ne );
for ( i=0; i<ne; i++ ) {
assert( r.getIndices()[i] == inx[i] );
assert( r.getElements()[i] == el[i] );
}
assert ( r.getMaxIndex()==7 );
assert ( r.getMinIndex()==1 );
// try to clear it
r.clear();
assert( r.indices_==NULL );
assert( r.elements_==NULL );
assert( r.nElements_==0 );
// Test setting/getting elements with indices out of order
const int ne2 = 5;
int inx2[ne2] = { 2, 4, 8, 14, 3 };
double el2[ne2] = { 2.2, 4.4, 6.6, 8.8, 3.3 };
r.setVector(ne2,inx2,el2);
assert( r.getNumElements()==ne2 );
for (i = 0; i < ne2; ++i) {
assert( r.getIndices()[i]==inx2[i] );
assert( r.getElements()[i]==el2[i] );
}
assert ( r.getMaxIndex()==14 );
assert ( r.getMinIndex()==2 );
// try to call it once more
assert ( r.getMaxIndex()==14 );
assert ( r.getMinIndex()==2 );
CoinShallowPackedVector r1(ne2,inx2,el2);
assert( r == r1 );
// assignment operator
r1.clear();
r1 = r;
assert( r == r1 );
// assignment from packed vector
CoinPackedVector pv1(ne2,inx2,el2);
r1 = pv1;
assert( r == r1 );
// construction
CoinShallowPackedVector r2(r1);
assert( r2 == r );
// construction from packed vector
CoinShallowPackedVector r3(pv1);
assert( r3 == r );
// test duplicate indices
{
const int ne3 = 4;
int inx3[ne3] = { 2, 4, 2, 3 };
double el3[ne3] = { 2.2, 4.4, 8.8, 6.6 };
r.setVector(ne3,inx3,el3, false);
assert(r.testForDuplicateIndex() == false);
bool errorThrown = false;
try {
r.setTestForDuplicateIndex(true);
}
catch (CoinError& e) {
errorThrown = true;
}
assert( errorThrown );
r.clear();
errorThrown = false;
try {
r.setVector(ne3,inx3,el3);
}
catch (CoinError& e) {
errorThrown = true;
//.........这里部分代码省略.........
开发者ID:e2bsq,项目名称:Symphony,代码行数:101,代码来源:CoinShallowPackedVectorTest.cpp
示例9: compute_hog_features
vector<HOG_BLOCK> compute_hog_features(Mat image, int kernel_cell_size, int block_size, int gaussian_blur_kernel)
{
int height = image.rows;
int width = image.cols;
vector<Mat> block_matrix;
Mat gradient_image;
Mat grad_x, grad_y;
vector<HOG_BLOCK> hog_blocks;
// Check for proper kernel size
if(height % kernel_cell_size > 0 || width % kernel_cell_size > 0) {
cerr << "Invalid kernel cell size." << endl;
return hog_blocks;
}
// Check for proper block size
int num_cells_height = height / kernel_cell_size;
int num_cells_width = width / kernel_cell_size;
if(num_cells_height % block_size > 0 || num_cells_width % block_size > 0) {
cerr << "Invalid block size." << endl;
return hog_blocks;
}
image.copyTo(gradient_image);
// Equalize histogram
equalizeHist(gradient_image, gradient_image);
// Gaussian blur kernel size
GaussianBlur(gradient_image, gradient_image, Size(gaussian_blur_kernel, gaussian_blur_kernel), 0, 0);
// Compute for gradient x-wise using Sobel operator
Sobel(gradient_image, grad_x, CV_32F, 1, 0, 3);
// Compute for graident y-wise using Sobel operator
Sobel(gradient_image, grad_y, CV_32F, 0, 1, 3);
// Compute for gradient orientation.
// Store in new gradient matrix.
Mat orientation_matrix(gradient_image.rows, gradient_image.cols, DataType<float>::type);
for(int i = 0; i < gradient_image.rows; i++) {
for(int j = 0; j < gradient_image.cols; j++) {
float gx = grad_x.at<float>(i,j);
float gy = grad_y.at<float>(i,j);
float orientation = atan(gy / (gx + 0.00001)) * (180 / 3.14) + 90;
orientation_matrix.at<float>(i, j) = orientation;
}
}
// Divide cells according to block size
for(int i = 0; i < width - (kernel_cell_size * block_size) + 1; i += (kernel_cell_size * block_size) / 2) {
for(int j = 0; j < height - (kernel_cell_size * block_size) + 1; j += (kernel_cell_size * block_size) / 2) {
Rect r(i, j, kernel_cell_size * block_size, kernel_cell_size * block_size);
Mat b_matrix = orientation_matrix(r);
block_matrix.push_back(b_matrix);
HOG_BLOCK hg;
hg.rect_block = r;
for(int row = 0; row < (kernel_cell_size * block_size); row += kernel_cell_size) {
for(int col = 0; col < (kernel_cell_size * block_size); col += kernel_cell_size) {
Rect r2(row, col, kernel_cell_size, kernel_cell_size);
Mat c_matrix = b_matrix(r2);
hg.cell_matrices.push_back(c_matrix);
}
}
hog_blocks.push_back(hg);
}
}
// Store histogram of oriented gradients per block
// Loop through each hog_block
// Loop through each cell of hog_block
// Get orientation of each pixel position in cell and increment corresponding bin
for(int i = 0; i < hog_blocks.size(); i++) {
for(int j = 0; j < hog_blocks.at(i).cell_matrices.size(); j++) {
vector<int> histogram_of_oriented_gradient;
histogram_of_oriented_gradient.resize(BIN_COUNT);
for(int row = 0; row < hog_blocks.at(i).cell_matrices.at(j).rows; row++) {
for(int col = 0; col < hog_blocks.at(i).cell_matrices.at(j).cols; col++) {
float o = hog_blocks.at(i).cell_matrices.at(j).at<float>(row, col);
if(o <= 20) {
histogram_of_oriented_gradient.at(0)++;
} else if(o > 20 && o <= 40) {
histogram_of_oriented_gradient.at(1)++;
} else if(o > 40 && o <= 60) {
histogram_of_oriented_gradient.at(2)++;
} else if(o > 60 && o <= 80) {
histogram_of_oriented_gradient.at(3)++;
} else if(o > 80 && o <= 100) {
histogram_of_oriented_gradient.at(4)++;
//.........这里部分代码省略.........
开发者ID:francisbautista,项目名称:opencv-utils,代码行数:101,代码来源:cvu_hog.cpp
示例10: shape
Collision::Collision(PObject* obj1, PObject* obj2)
{
trueCollision = false;
objects = new PObject*[2];
objects[0] = obj1;
objects[1] = obj2;
/*
* the following was written before the Vect2D class was written
* (and that's why it's so messy)
*/
Vect2D norm;
Point p1,p2;
const Point* obj1vertices = objects[0]->getVertices();
const Point* obj2vertices = objects[1]->getVertices();
int numPoints=0;
float sumx=0;
float sumy=0;
float parametric;
float parametric2;
float denominator;
float vec1x;
float vec1y;
float vec1deltax;//between this point and the next one in the shape (going counterclockwise)
float vec1deltay;
float vec2x;
float vec2y;
float vec2deltax;
float vec2deltay;
float deltax, deltay; //between the two points on different shapes
/*
* x1+k*t = x2+c*k
* y1+b*t = y2+d*k
*/
for (int i = 0; i < objects[0]->getNumVertices(); i++)
{
vec1x = obj1vertices[i].x;//x1
vec1y = obj1vertices[i].y;//y1
vec1deltax = obj1vertices[(i + 1) % objects[0]->getNumVertices()].x - vec1x;//a
vec1deltay = obj1vertices[(i + 1) % objects[0]->getNumVertices()].y - vec1y;//b
for (int j = 0; j < objects[1]->getNumVertices(); j++)
{
vec2x = obj2vertices[j].x;//x2
vec2y = obj2vertices[j].y;//y2
vec2deltax = obj2vertices[(j + 1) % objects[1]->getNumVertices()].x - vec2x;//c
vec2deltay = obj2vertices[(j + 1) % objects[1]->getNumVertices()].y - vec2y;//d
denominator = (vec1deltax * vec2deltay) - (vec2deltax * vec1deltay);//ad-bc
if (denominator != 0)
{
deltax = vec1x-vec2x;//x1-x2
deltay = vec1y-vec2y;//y1-y2
parametric = ((vec2deltax * (deltay)) - vec2deltay * (deltax)) / (denominator);//t
parametric2 = ((vec1deltax * (deltay)) - vec1deltay * (deltax)) / (denominator);//k
if (parametric <= 1 && parametric >= 0 && parametric2 <= 1 && parametric2 >= 0)
{
numPoints++;
sumx += vec1x + (parametric * vec1deltax);//x = x1+a*t
sumy += vec1y + (parametric * vec1deltay);//y = y1+b*t
//uses the normal vector of the first collision
if (!trueCollision){
/* old way of finding
//figure out which one collided on the corner
if (abs(parametric2-.5) < abs(parametric-.5)){
//vector1's point of collision was closer to the corner
norm.set(vec2deltay,-vec2deltax);
}
else
{
norm.set(vec2deltax,-vec2deltay);
}*/
//VERY crude approximation for normal vector at collision point
norm.set(objects[1]->get_centerx()-objects[0]->get_centerx(), objects[1]->get_centery()-objects[0]->get_centery());
norm.normalize();
}
trueCollision = true;
}
}
}
}
if (trueCollision)
{
intersection.x = sumx/numPoints;
intersection.y = sumy/numPoints;
//calculate impulse here
float e = objects[0]->get_elasticity()*objects[1]->get_elasticity();
Vect2D r1(intersection.x-objects[0]->get_centerx(), intersection.y-objects[0]->get_centery());
Vect2D r2(intersection.x-objects[1]->get_centerx(), intersection.y-objects[1]->get_centery());
//.........这里部分代码省略.........
开发者ID:babymastodon,项目名称:Physics2D,代码行数:101,代码来源:Collision.cpp
示例11: tile
void tile(int neXindex, int neYindex, int N, int holeX, int holeY)
{
if(N==2)
{
Color c=rColor();
if(flag==0)
c=COLOR("White");
if(holeX!=neXindex || holeY!=neYindex)
{
Rectangle r3(neXindex*W + W/2,neYindex*W + W/2,W,W);
r3.setFill();
r3.setColor(c);
r3.imprint();
}
if(holeX!=neXindex || holeY!=neYindex+1)
{
Rectangle r1(neXindex*W + W/2,neYindex*W + 3*W/2,W,W);
r1.setFill();
r1.setColor(c);
r1.imprint();
}
if(holeX!=neXindex+1 || holeY!=neYindex+1)
{
Rectangle r2(neXindex*W + 3*W/2,neYindex*W + 3*W/2,W,W);
r2.setFill();
r2.setColor(c);
r2.imprint();
}
if(holeX!=neXindex+1 || holeY!=neYindex)
{
Rectangle r3(neXindex*W + 3*W/2,neYindex*W + W/2,W,W);
r3.setFill();
r3.setColor(c);
r3.imprint();
}
}
else
{
if(neXindex<=holeX && holeX<neXindex+N/2 && neYindex<=holeY && holeY<neYindex+N/2) //Bottom Left
{
tile(neXindex,neYindex,N/2,holeX,holeY);
tile(neXindex,neYindex+N/2,N/2,neXindex-1+N/2,neYindex+N/2);
tile(neXindex+N/2,neYindex+N/2,N/2,neXindex+N/2,neYindex+N/2);
tile(neXindex+N/2,neYindex,N/2,neXindex+N/2,neYindex-1+N/2);
flag=0;
tile(neXindex-1+N/2,neYindex-1+N/2,2,neXindex-1+N/2,neYindex-1+N/2);
flag=1;
}
else if(neXindex<=holeX && holeX<neXindex+N/2 && holeY>=neYindex+N/2 && holeY<neYindex+N) //Top Left
{
tile(neXindex,neYindex+N/2,N/2,holeX,holeY);
tile(neXindex,neYindex,N/2,neXindex-1+N/2,neYindex-1+N/2);
tile(neXindex+N/2,neYindex+N/2,N/2,neXindex+N/2,neYindex+N/2);
tile(neXindex+N/2,neYindex,N/2,neXindex+N/2,neYindex-1+N/2);
flag=0;
tile(neXindex-1+N/2,neYindex-1+N/2,2,neXindex-1+N/2,neYindex+N/2);
flag=1;
}
else if(holeX>=neXindex+N/2 && holeX<neXindex+N && holeY>=neYindex+N/2 && holeY<neYindex+N) //Top Right
{
tile(neXindex+N/2,neYindex+N/2,N/2,holeX,holeY);
tile(neXindex,neYindex,N/2,neXindex-1+N/2,neYindex-1+N/2);
tile(neXindex,neYindex+N/2,N/2,neXindex-1+N/2,neYindex+N/2);
tile(neXindex+N/2,neYindex,N/2,neXindex+N/2,neYindex-1+N/2);
flag=0;
tile(neXindex-1+N/2,neYindex-1+N/2,2,neXindex+N/2,neYindex+N/2);
flag=1;
}
else //if(holeX>=neXindex+N/2 && holeX<neXindex+N && neYindex<=holeY && holeY<neYindex+N/2) //Bottom Right
{
tile(neXindex+N/2,neYindex,N/2,holeX,holeY);
tile(neXindex,neYindex,N/2,neXindex-1+N/2,neYindex-1+N/2);
tile(neXindex,neYindex+N/2,N/2,neXindex-1+N/2,neYindex+N/2);
tile(neXindex+N/2,neYindex+N/2,N/2,neXindex+N/2,neYindex+N/2);
flag=0;
tile(neXindex-1+N/2,neYindex-1+N/2,2,neXindex+N/2,neYindex-1+N/2);
flag=1;
}
}
}
开发者ID:db-coder,项目名称:Tiling,代码行数:80,代码来源:130050046.cpp
示例12: k951_connect
static void k951_connect ( PIA *pi )
{ pi->saved_r0 = r0();
pi->saved_r2 = r2();
w2(4);
}
开发者ID:CSCLOG,项目名称:beaglebone,代码行数:6,代码来源:kbic.c
示例13: reorder
std::vector<int> reorder(MatrixType const & matrix,
advanced_cuthill_mckee_tag const & tag)
{
std::size_t n = matrix.size();
double a = tag.starting_node_param();
std::size_t gmax = tag.max_root_nodes();
std::vector<int> r;
std::vector<int> r_tmp;
std::vector<int> r_best;
std::vector<int> r2(n);
std::vector<bool> inr(n, false);
std::vector<bool> inr_tmp(n);
std::vector<bool> inr_best(n);
std::deque<int> q;
std::vector< std::vector<int> > nodes;
std::vector<int> nodes_p;
std::vector<int> tmp(2);
std::vector< std::vector<int> > l;
int deg_min;
int deg_max;
int deg_a;
int deg;
int bw;
int bw_best;
std::vector<int> comb;
std::size_t g;
int c;
r.reserve(n);
r_tmp.reserve(n);
r_best.reserve(n);
nodes.reserve(n);
nodes_p.reserve(n);
comb.reserve(n);
do
{
// add to nodes_p all nodes not yet in r which are candidates for the root node layer
// search unnumbered node and generate layering
for (std::size_t i = 0; i < n; i++)
{
if (!inr[i])
{
detail::generate_layering(matrix, l, i);
break;
}
}
nodes.resize(0);
for (std::vector< std::vector<int> >::iterator it = l.begin();
it != l.end(); it++)
{
for (std::vector<int>::iterator it2 = it->begin();
it2 != it->end(); it2++)
{
tmp[0] = *it2;
tmp[1] = matrix[*it2].size() - 1;
nodes.push_back(tmp);
}
}
// determine minimum and maximum node degree
deg_min = -1;
deg_max = -1;
for (std::vector< std::vector<int> >::iterator it = nodes.begin();
it != nodes.end(); it++)
{
deg = (*it)[1];
if (deg_min < 0 || deg < deg_min)
{
deg_min = deg;
}
if (deg_max < 0 || deg > deg_max)
{
deg_max = deg;
}
}
deg_a = deg_min + (int) (a * (deg_max - deg_min));
nodes_p.resize(0);
for (std::vector< std::vector<int> >::iterator it = nodes.begin();
it != nodes.end(); it++)
{
if ((*it)[1] <= deg_a)
{
nodes_p.push_back((*it)[0]);
}
}
inr_tmp = inr;
g = 1;
comb.resize(1);
comb[0] = 1;
bw_best = -1;
for (;;) // for all combinations of g <= gmax root nodes repeat
{
inr = inr_tmp;
r_tmp.resize(0);
// add the selected root nodes according to actual combination comb to q
for (std::vector<int>::iterator it = comb.begin();
it != comb.end(); it++)
//.........这里部分代码省略.........
开发者ID:AngeloTorelli,项目名称:CompuCell3D,代码行数:101,代码来源:cuthill_mckee.hpp
示例14: equivalent
/*! This method does the same as PP_AttrProp::isEquivalent(const PP_AttrProp *) except
that instead of being passed another AP to be compared to, it is passed sets of
attributes and properties which only virtually comprise another AP.
\retval TRUE if equivalent (regardless of order) to given Attrs and Props, FALSE otherwise.
*/
bool PP_AttrProp::isEquivalent(const gchar ** attrs, const gchar ** props) const
{
UT_uint32 iAttrsCount = 0;
UT_uint32 iPropsCount = 0;
const gchar ** p = attrs;
while(p && *p)
{
iAttrsCount++;
p += 2;
}
p = props;
while(p && *p)
{
iPropsCount++;
p += 2;
}
if( getAttributeCount() != iAttrsCount
|| getPropertyCount() != iPropsCount)
return false;
UT_uint32 i;
const gchar * pName, * pValue, * pValue2;
for(i = 0; i < getAttributeCount(); ++i)
{
pName = attrs[2*i];
pValue = attrs[2*i + 1];
if(!getAttribute(pName,pValue2))
return false;
// ignore property attribute
if(0 == strcmp(pValue, PT_PROPS_ATTRIBUTE_NAME))
continue;
// handle revision attribute correctly
if(0 == strcmp(pValue, PT_REVISION_ATTRIBUTE_NAME))
{
// requires special treatment
PP_RevisionAttr r1(pValue);
PP_RevisionAttr r2 (pValue2);
if(!(r1 == r2))
{
return false;
}
}
else if(0 != strcmp(pValue,pValue2))
return false;
}
for(i = 0; i < getPropertyCount(); ++i)
{
pName = props[2*i];
pValue = props[2*i + 1];
if(!getProperty(pName,pValue2))
return false;
if(0 != strcmp(pValue,pValue2))
return false;
}
return true;
}
开发者ID:tanya-guza,项目名称:abiword,代码行数:76,代码来源:pp_AttrProp.cpp
示例15: file
void scnreader_model::createRail()
{
QString noms=this->nomFile;
noms.push_back("_switch.txt");
//open the file
QFile file(noms);
if(!this->nuage.isEmpty())
{
if(this->cfs || !file.exists())
{
// //---------------JJ
// if(ftpf>this->ftpd+500)
// ftpf=this->ftpd+500;
// //-----------------
//---------------initialize footpulses which determine the beginning and the end of window-----------
int dw=this->ftpd+1;
int fw;
if(this->ftpf-this->ftpd<workWindows)
fw=this->ftpf;
else
fw=this->ftpd+workWindows;
std::cout << dw << " - " << fw<<std::endl;
//-------------------------------we initialize Listerail----------------------------------------------
//create rails with the first footpulse
RailCluster r (0.18,0.08,1.5,*this->nuage.value(this->ftpd));
RailCluster rc=r;
this->lesRails.addRail(r);
//and we add the others until the footpulse fw, so window is ftpd - (fw-1)
for(int i=dw; i<fw;i++)
{
RailCluster r2(0.18,0.08,1.5,* (this->nuage.value(i)), rc);
rc=r2;
this->lesRails.addRail(r2);
}
//cleanNoise(fw);
this->optimization();
//we keep detected switch in this window
int nbswitch=this->lesRailsOptimize.getSwitchDetected().size();
for(int i=0; i<nbswitch;i++)
{
int ftp=this->lesRailsOptimize.getSwitchDetected().at(i);
if(!this->LesSwitchs.contains(ftp))
{
this->LesSwitchs.push_back(ftp);
}
}
//we reinit lesRailsOptimize et resultRansac
this->lesRailsOptimize.clear();
this->resultRANSAC->clear();
//we continue to cover all the cloud with a window which we move footpulse by footpulse
while(fw<=this->ftpd+3)//this->ftpf
{
//we add a new track and remove the first in track in window
RailCluster r2(0.18,0.08,1.5,* (this->nuage.value(fw)), rc);
rc=r2;
this->lesRails.addRail(r2);
//we do the treatment to detect switchs in this window
this->optimization();
//we keep detected switch in this window
nbswitch=this->lesRailsOptimize.getSwitchDetected().size();
for(int i=0; i<nbswitch;i++)
{
int ftp=this->lesRailsOptimize.getSwitchDetected().at(i);
//we verify that the size of vector doesn't exceed the cvector's capacity
if(this->LesSwitchs.size()<this->capacity)
{
if(!this->LesSwitchs.contains(ftp))
this->LesSwitchs.push_back(ftp);
}
//if it exceeds
else
{
//----------------we write footpulses in a text file
VideEtEnregistre(noms);
}
}
//we reinit lesRailsOptimize et resultRansac
//this->lesRailsOptimize.clear();
//this->resultRANSAC->clear();
//we move the window
dw++;
fw++;
}
//----------------we write footpulses of switch in a text file
this->enregistre(noms);
}
}
else throw Erreur("Les rails n'ont pas pu etre crees car le nuage de points est vide.");
}
开发者ID:JJponciano,项目名称:789789456856hnfjydhdr,代码行数:100,代码来源:scnreader_model.cpp
示例16: painter
void WorkPlaceWidget::drawEntitie(Entitie* e, bool focus, bool isAbstract){
this->calculateEntitie(e);
int x = ((IntField*)e->fieldByID("X"))->getValue();
int y = ((IntField*)e->fieldByID("Y"))->getValue();
int w = ((IntField*)e->fieldByID("W"))->getValue();
int h = ((IntField*)e->fieldByID("H"))->getValue();
int t = ((IntField*)e->fieldByID("T"))->getValue();
bool mov = true;
for(int i=0; i<this->core->getEntitieCount(); i++){
Entitie* e0 = this->core->getEntitieAt(i);
int xe = ((IntField*)e0->fieldByID("X"))->getValue();
int ye = ((IntField*)e0->fieldByID("Y"))->getValue();
int we = ((IntField*)e0->fieldByID("W"))->getValue();
int he = ((IntField*)e0->fieldByID("H"))->getValue();
if((xe-w-15<x)&&(ye-h-15<y)&&(we+xe+15>x)&&(he+ye+15>y)&&(e0!=e)){
mov = false;
}
}
int alpha = (((isAbstract)||(!mov)) ? 20 : 250);
int alpha0 = (((isAbstract)||(!mov)) ? 0 : 25);
int alpha1 = (((isAbstract)||(!mov)) ? 0 : 100);
if(isAbstract){
((IntField*)e->fieldByID("X"))->setValue(this->curX);
((IntField*)e->fieldByID("Y"))->setValue(this->curY);
}
QPainter painter(this);
QColor color(255,200,125,alpha);
QColor color1(255,170,100,alpha);
QColor color2(215,215,255,alpha);
QColor colorRed(252,139,130,alpha);
QColor colorGreen(125,220,125,alpha);
QColor colorGreenAlpha(55,155,55,alpha0);
QColor colorBlackAlpha(0,0,0,alpha1);
QPen pen1 = QPen(Qt::black, 1, Qt::SolidLine);
QPen pen2 = QPen(colorBlackAlpha, 1, Qt::SolidLine);
painter.setPen(pen1);
if(this->core->getState()==10 && this->core->getWeightOfSolution()!=-1){
bool green = false;
for(int i=0; i<this->core->getBestWay()->size(); i++){
if(e->getID()==this->core->getBestWay()->at(i)){
green = true;
}
}
if(t!=1){
if(green){
painter.setBrush(QBrush(colorGreen));
}else{
painter.setBrush(QBrush(colorRed));
}
}else{
painte
|
请发表评论