想将我的c ++代码转换为Dot net中的c#窗体应用程序 [英] Wanna Convert my c++ code to c# window form application in Dot net

查看:49
本文介绍了想将我的c ++代码转换为Dot net中的c#窗体应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include" stdafx.h"

#include" recording.h"



Recording :: Recording(): width(1),height(1),candidateStartTime(0),maximumFrameCount(0),frameCount(0),tail(0),statMinimum(5){

stanceCentre.x = 0;

stanceCentre.y = 0;

standingMaximum = 100;

}



记录: :〜Recording(){

clear();

if(frames)delete [] frames;

}



bool Recording :: setMaximumFrameCount(int count ){

if(count!= maximumFrameCount){

clear();

if(frames)delete [] frames;

frames = new Frame * [count];

if(frames){

maximumFrameCount = count;

memset(frames,0,count * sizeof(Frame *));

}

else maximumFrameCount = 0;

frameCount = 0;

tail = 0;

candidateStartTime = 0;

}

返回计数== maximumFrameCount;

}



void Recording :: setSensorDimensions(int width,int height){

this-> ; width = width;

this-> height = height;

stanceCentre.x = width / 2.0f;

stanceCentre.y = height / 2.0f;

candidateStartTime = 0 ; $
}



点记录:: getStanceCentre(){

return stanceCentre;

}



float Recording :: getStandingMaximum(){

return standingMaximum;

}



bool录制:: checkStanceCentre(Frame * frame){

float distance =(frame-> copPosition.x - stanceCentre.x)*(frame - > copPosition.x - stanceCentre.x)+(frame-> copPosition.y - stanceCentre.y)*(frame-> copPosition.y - stanceCentre.y);

if(distance< 100)candidateStartTime = 0;

否则if(candidateStartTime == 0){

candidateCentre.x = frame-> copPosition.x;

candidateCentre .y = frame-> copPosition.y;

candidateStartTime = frame-> time;

}

其他{

距离=(frame-> copPosition.x - candidateCentre.x)*(frame-> copPosition.x - candidateCentre.x)+(frame - > copPosition.y - candidateCentre.y)*(frame-> copPosition.y - candidateCentre.y);

if(距离< 100){

if(frame-> time - candidateStartTime> 2.0){

stanceCentre.x = candidateCentre.x;

stanceCentre.y = candidateCentre.y;

candidateStartTime = 0 ;

standingMaximum = frame-> maximum;

返回true;

}

}

else candidateStartTime = 0;

}

返回false;

}



void Recording :: calculateWeightSplits(Frame * frame){

int columns = frame-> columns;

int rows = frame-> rows;

float total = 0,leftTotal = 0,leftHeelTotal = 0,rightHeelTotal = 0;

float sensorWidth = float( width)/ columns,sensorHeight = float(height)/ rows;

int heelColumns = int(stanceCentre.x / sensorWidth);

float heelFraction = stanceCentre.x / sensorWidth - heelColumns;

int leftRows = int((height - stanceCentre.y)/ sensorHeight);

float leftFraction =(height - stanceCentre.y)/ sensorHeight - leftRows;

float * value = frame-> values;

for(int r = 0; r<行; ++ r)

for(int c = 0; c< columns; ++ c,++ value)

if(* value> = statMinimum){

总计+ = *值;

if(r == leftRows){

float v = * value * leftFraction;

leftTotal + = v;

if(c == heelColumns){

leftHeelTotal + = v * heelFraction;

rightHeelTotal + =(* value - v )* heelFraction;

}

else if(c< heelColumns){

leftHeelTotal + = v;

< span style ="white-space:pre"> rightHeelTotal + =(* value - v);

}

}

else if(r< leftRows){

leftTotal + = * value;

if(c< = heelColumns){

if(c == heelColumns)leftHeelTotal + = * value * heelFraction;

else leftHeelTotal + = * value;

}

}

else if(c< = heelColumns){

if(c == heelColumns )rightHeelTotal + = * value * heelFraction;

else rightHeelTotal + = * value;

}

}



if(total> 0){

frame-> weightSplit = leftTotal / total;

frame-> leftWeightSplit = leftTotal> 0? leftHeelTotal / leftTotal:0.5f;

frame-> rightWeightSplit =(total - leftTotal)> 0? rightHeelTotal /(total - leftTotal):0.5f;

}

else {

frame-> weightSplit = 0.5f;

frame-> leftWeightSplit = 0.5f;

frame-> rightWeightSplit = 0.5f;

}

}



void Recording :: setStatMinimum(float statMinimum){

int f;

this-> statMinimum = statMinimum;

for(f = frameCount - 1; f> = 0; --f)calculateWeightSplits(getFrame(f));

}



int Recording :: getFrameCount(){

return frameCount;

}



Frame * Recording :: getFrame(int f){

if(!frames)返回NULL;

返回帧[( tail + f)%maximumFrameCount];

}
$


int Recording :: addFrame(Frame * frame){

if(!frames)返回0;

int head =(tail + frameCount)%maximumFrameCount;

Frame * oldFrame = frames [head];

if(oldFrame)delete oldFrame;

帧[head] = frame;

//微调速度值

if(frameCount> 4){

帧* back1 = frames [(head + frameCount - 1)%frameCount];

Frame * back2 = frames [(head + frameCount - 2)%frameCount];

Frame * back3 = frames [(head + frameCount - 3)%frameCount];

Frame * back4 = frames [(head + frameCount - 4)%frameCount];

double interval =(frame-> time + back1-> time)/ 2 - (back3-> time + back4-> time)/ 2;

if(interval> 0){

back2-> copVelocity.x = float(((frame-> copPosition。 x + back1-> copPosition.x)/ 2 - (back3-> copPosition.x + back4-> copPosition.x)/ 2)/ interval);

back2-> copVelocity.y = float(((frame-> copPosition.y + back1-> copPosition.y)/ 2 - (ba ck3-> copPosition.y + back4-> copPosition.y)/ 2)/ interval);

}

}

if(checkStanceCentre (frame)){//如果原点已经改变,则重新计算整个记录的权重分割

for(int i = 0 ;我< ,帧数; ++ i)calculateWeightSplits(getFrame(i));

standingMaximum = frame-> maximum;

}

否则calculateWeightSplits(frame);

if(frameCount< maximumFrameCount)frameCount ++;

else tail =(tail + 1)%maximumFrameCount;

返回frameCount;

}
$


void Recording :: clear(){

if(!frames)return;

for(int i = 0; i< frameCount; ++ i)delete getFrame (i);

memset(frames,0,maximumFrameCount * sizeof(Frame *));

frameCount = 0;

tail = 0;

解决方

我看不到的问题。您需要说明要解决的具体问题。


请注意,您还需要将问题放在问题的正文中,而不是主题。当主题用于提出整个问题时,超过90%的时间问题需要澄清。该主题的最佳用途是使其尽可能短
,但足以帮助那些有助于决定查看它的人。


#include "stdafx.h"
#include "recording.h"

Recording::Recording() : width(1), height(1), candidateStartTime(0), maximumFrameCount(0), frameCount(0), tail(0), statMinimum(5) {
stanceCentre.x = 0;
stanceCentre.y = 0;
standingMaximum = 100;
}

Recording::~Recording() {
clear();
if (frames) delete[] frames;
}

bool Recording::setMaximumFrameCount(int count) {
if (count != maximumFrameCount) {
clear();
if (frames) delete[] frames;
frames = new Frame*[count];
if (frames) {
maximumFrameCount = count;
memset(frames, 0, count * sizeof(Frame*));
}
else maximumFrameCount = 0;
frameCount = 0;
tail = 0;
candidateStartTime = 0;
}
return count == maximumFrameCount;
}

void Recording::setSensorDimensions(int width, int height) {
this->width = width;
this->height = height;
stanceCentre.x = width / 2.0f;
stanceCentre.y = height / 2.0f;
candidateStartTime = 0;
}

Point Recording::getStanceCentre() {
return stanceCentre;
}

float Recording::getStandingMaximum() {
return standingMaximum;
}

bool Recording::checkStanceCentre(Frame* frame) {
float distance = (frame->copPosition.x - stanceCentre.x) * (frame->copPosition.x - stanceCentre.x) + (frame->copPosition.y - stanceCentre.y) * (frame->copPosition.y - stanceCentre.y);
if (distance < 100) candidateStartTime = 0;
else if (candidateStartTime == 0) {
candidateCentre.x = frame->copPosition.x;
candidateCentre.y = frame->copPosition.y;
candidateStartTime = frame->time;
}
else {
distance = (frame->copPosition.x - candidateCentre.x) * (frame->copPosition.x - candidateCentre.x) + (frame->copPosition.y - candidateCentre.y) * (frame->copPosition.y - candidateCentre.y);
if (distance < 100) {
if (frame->time - candidateStartTime > 2.0) {
stanceCentre.x = candidateCentre.x;
stanceCentre.y = candidateCentre.y;
candidateStartTime = 0;
standingMaximum = frame->maximum;
return true;
}
}
else candidateStartTime = 0;
}
return false;
}

void Recording::calculateWeightSplits(Frame* frame) {
int columns = frame->columns;
int rows = frame->rows;
float total = 0, leftTotal = 0, leftHeelTotal = 0, rightHeelTotal = 0;
float sensorWidth = float(width) / columns, sensorHeight = float(height) / rows;
int heelColumns = int(stanceCentre.x / sensorWidth);
float heelFraction = stanceCentre.x / sensorWidth - heelColumns;
int leftRows = int((height - stanceCentre.y) / sensorHeight);
float leftFraction = (height - stanceCentre.y) / sensorHeight - leftRows;
float* value = frame->values;
for (int r = 0; r < rows; ++r)
for (int c = 0; c < columns; ++c, ++value)
if (*value >= statMinimum) {
total += *value;
if (r == leftRows) {
float v = *value * leftFraction;
leftTotal += v;
if (c == heelColumns) {
leftHeelTotal += v * heelFraction;
rightHeelTotal += (*value - v) * heelFraction;
}
else if (c < heelColumns) {
leftHeelTotal += v;
rightHeelTotal += (*value - v);
}
}
else if (r < leftRows) {
leftTotal += *value;
if (c <= heelColumns) {
if (c == heelColumns) leftHeelTotal += *value * heelFraction;
else leftHeelTotal += *value;
}
}
else if (c <= heelColumns) {
if (c == heelColumns) rightHeelTotal += *value * heelFraction;
else rightHeelTotal += *value;
}
}

if (total > 0) {
frame->weightSplit = leftTotal / total;
frame->leftWeightSplit = leftTotal > 0 ? leftHeelTotal / leftTotal : 0.5f;
frame->rightWeightSplit = (total - leftTotal) > 0 ? rightHeelTotal / (total - leftTotal) : 0.5f;
}
else {
frame->weightSplit = 0.5f;
frame->leftWeightSplit = 0.5f;
frame->rightWeightSplit = 0.5f;
}
}

void Recording::setStatMinimum(float statMinimum) {
int f;
this->statMinimum = statMinimum;
for (f = frameCount - 1; f >= 0; --f) calculateWeightSplits(getFrame(f));
}

int Recording::getFrameCount() {
return frameCount;
}

Frame* Recording::getFrame(int f) {
if (!frames) return NULL;
return frames[(tail + f) % maximumFrameCount];
}

int Recording::addFrame(Frame* frame) {
if (!frames) return 0;
int head = (tail + frameCount) % maximumFrameCount;
Frame* oldFrame = frames[head];
if (oldFrame) delete oldFrame;
frames[head] = frame;
// fine tune the velocity values
if (frameCount > 4) {
Frame* back1 = frames[(head + frameCount - 1) % frameCount];
Frame* back2 = frames[(head + frameCount - 2) % frameCount];
Frame* back3 = frames[(head + frameCount - 3) % frameCount];
Frame* back4 = frames[(head + frameCount - 4) % frameCount];
double interval = (frame->time + back1->time) / 2 - (back3->time + back4->time) / 2;
if (interval > 0) {
back2->copVelocity.x = float(((frame->copPosition.x + back1->copPosition.x) / 2 - (back3->copPosition.x + back4->copPosition.x) / 2) / interval);
back2->copVelocity.y = float(((frame->copPosition.y + back1->copPosition.y) / 2 - (back3->copPosition.y + back4->copPosition.y) / 2) / interval);
}
}
if (checkStanceCentre(frame)) { // if the origin has changed then recalculate the weight splits for entire recording
for (int i = 0; i < frameCount; ++i) calculateWeightSplits(getFrame(i));
standingMaximum = frame->maximum;
}
else calculateWeightSplits(frame);
if (frameCount < maximumFrameCount) frameCount++;
else tail = (tail + 1) % maximumFrameCount;
return frameCount;
}

void Recording::clear() {
if (!frames) return;
for (int i = 0; i < frameCount; ++i) delete getFrame(i);
memset(frames, 0, maximumFrameCount * sizeof(Frame*));
frameCount = 0;
tail = 0;

解决方案

I don't see a question. You need to state a specific problem to be solved.

Note that you also need to put your question in the body of the question, not the subject. When the subject is used to ask the entire question then more than 90% of the time the question needs clarification. The best use of the subject is to make it as short as possible yet adequate enough to help those that can help to decide to look at it.


这篇关于想将我的c ++代码转换为Dot net中的c#窗体应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆