Simply_Red said:
i'm sorry i posted this in other groupes, and i didn't see it, and as
this group is most actif, i repost it here, and sorry for
mutliposting:
Hi,
i'm using VC6, i have this declaration:
typedef struct tagTLimite {
double Debut;
double Fin;
}Limites;
typedef struct TagElemTab {
double NivY;
bool Existe;
std::vector<Limites> PtLimites;
}ElemTabCont;
void myfunc( )
{
.....
ElemTabCont * ContNonOrd;//contour non ordone
long nbNiveau = (yhi-ylo)/stepY +1 ;
ContNonOrd = new ElemTabCont [nbNiveau];
.....
}
i don't know why,nbNiveau is equal to (yhi-ylo)/stepY, it didn't
+1????and even if i put:
How did you tell? Probably you misinterpret some output that we do not see
because your code snippet is incomplete.
and even if i put: ContNonOrd = new ElemTabCont [nbNiveau+1]; the size of
ContNonOrd = nbNiveau????
Again, how did you tell?
Please post a minimal complete program that shows the problem. With the code
fragments from above, there is no way to tell what the problem is
(especially since we do not even know the types of yhi, yhl, and stepY.
Best
Kai-Uwe Bux
bool __declspec(dllexport) CALLBACK NewMakeContour(LPSAFEARRAY FAR
*saY, VARIANT FAR *pvArray, double yhi, double ylo,double stepX,double
stepY)
{
SAFEARRAYBOUND sabound[1]; // 1-D array
SAFEARRAY FAR* psa = NULL; // SAFEARRAY structure pointer
HRESULT hr; // Operations result
float HUGEP *vbY; // Tableau Contenant tous les points
long UboundY;
double V;
long ptTabRes,ptTabSource;
hr = SafeArrayAccessData(*saY, (void HUGEP**)&vbY);
UboundY = (*saY)->rgsabound[0].cElements;
ElemTabCont * ContNonOrd;//contour non ordone
long nbNiveau = (yhi-ylo)/stepY+1 ;// +1 ; je ne sais pas pourquoi il
ne me fait pas le + 1;
ContNonOrd = new ElemTabCont[nbNiveau];
//ContNonOrd = new ElemTabCont[161];//donc je suis obliger de le
faire ici
V = vbY[1];//le premier pt est un pt du contour
ptTabRes = 0;
ptTabSource = 0;
while (FRound(V,3) <= FRound(yhi,3))
{
FindLevelPt(vbY, ptTabSource,ContNonOrd,ptTabRes,V,UboundY,stepX);
ptTabRes++;
V+=stepY;
}
delete[] ContNonOrd;
hr = SafeArrayUnaccessData(*saY);
return true
}
void FindLevelPt(float* TabSource, long& ptTabSource,ElemTabCont*
ContNonOrd,long ptTabRes,double V, long UBoundY, float StepX) {
Limites XLimites;
ContNonOrd[ptTabRes].NivY = V;
//si on est au niv superieur a V=>pas de point au niveau V
if (FRound(TabSource[ptTabSource+1],3) == FRound(V,3))
{
ContNonOrd[ptTabRes].Existe = true;
bool nivDepasse = false;
bool terminer = false;
while (!nivDepasse && !terminer)
{
XLimites.Debut = TabSource[ptTabSource];
bool trouve = false;//true si on trouve la limite du segment
ptTabSource+=3;//le debut a ete deja trouver
while(!trouve && ptTabSource <= UBoundY-3) //-1 z, -2 y -3 x
{
nivDepasse = (FRound(TabSource[ptTabSource+1],3) > FRound(V,3));
trouve = (FRound(TabSource[ptTabSource]-TabSource[ptTabSource-3],
3)>FRound(StepX,3)) || nivDepasse ;
ptTabSource+=3;
}
if (trouve) {
XLimites.Fin = TabSource[ptTabSource-6];
ptTabSource-=3;//pour pointer au prochain debut.
ContNonOrd[ptTabRes].PtLimites.push_back(XLimites);
}
else {//le dernier pt ou la derniere ligne
terminer = true;
XLimites.Fin = TabSource[ptTabSource-3];
ContNonOrd[ptTabRes].PtLimites.push_back(XLimites);
}
}
}
else ContNonOrd[ptTabRes].Existe = false;
}