Ciao ragazzi,
sono nuovo del forum e vi vorrei subito chiede una mano
Devo consegnare tra pochi giorni un progetto di grafica scritto in c/c++...ho già fatto tutto e funziona. Il progetto si appoggia però a un altro progetto svolto da terze parti anni fa che non compilava ma cmq pensavo di risolvere in poco tempo.. ed invece eccomi con una valanga di error che non so come risolvere. Il problema sta nel fatto che il tizio fece uso massiccio di template per l'implementazione di NURBS, e io coi template sto purtroppo a zero
cerco di postarvi una parte di codice più chiaramente possibile...
// File knot_par.cpp
#include <iostream.h>
#include <stdlib.h>
#include "knot_par.h"
/* Constructor parameters:
* pt=partition type
* ct=more knots type
*/
knot_partition::knot_partition(int degree,int kn,int pt,int ct)
{
int i;
double h;
m=degree;
knot_number=kn;
if (knot_number<2*m) {
cerr << "\nNot enough knots: program aborted...\n";
exit(1);
}
k.change_dimension(kn);
if (ct==COINCIDENT) {
more_knots_type=COINCIDENT;
for (i=0; i<=m-1; i++)
k(i)=AA;
for (i=knot_number-1; i>=knot_number-m; i--)
k(i)=BB;
}
else {
/* Find this space with C++ code to support new disposition of knots */
}
if (pt==UNIFORM) {
partition_type=UNIFORM;
h=(BB-AA)/(knot_number-2*m+1);
for (i=m; i<knot_number-m; i++)
k(i)=((i-m+1)*h);
}
else {
/* Find this space with C++ code to support new partition types */
}
range_number=rn();
first_k=0;
}
knot_partition::knot_partition(int degree,vector<double>& data)
{
int l;
m=degree;
knot_number=data.get_dim();
k.change_dimension(knot_number);
k=data;
range_number=rn();
l=0;
while (k(l)!=0.0)
++l;
first_k=l;
}
knot_partition::~knot_partition()
{
}
/* Number of range nodes*/
/* WARNING: variable u is in [0,1] */
int knot_partition::rn()
{
int i;
int sum=0;
i=0;
while (k(i)!=AA)
++i;
while (k(i)!=BB) {
if (k(i)!=k(i+1))
++sum;
++i;
}
return sum;
}
int knot_partition::get_degree()
{
return m;
}
int knot_partition::get_knot_number()
{
return knot_number;
}
double knot_partition::get_knot_value(int knot_index)
{
return k(knot_index);
}
int knot_partition::get_knot_molt(double u)
{
int molt;
register int i,j;
molt=0;
for (i=0; i<knot_number && u!=k(i); i++)
;
j=i;
while (u==k(j++))
molt++;
return molt;
}
void knot_partition::range(double u,double *r)
{
int i,found;
i=found=0;
while (i<knot_number-1 && !found) {
if (u>=k(i) && u<k(i+1))
++found;
else
++i;
}
if (!found && u==k(knot_number-1)) { /* It controls the last node: a special situation */
i=knot_number-2;
while (k(knot_number-1)==k(i))
i--;
}
r[0]=k(i);
r[1]=k(i+1);
}
double knot_partition::BSpline(int n,double u)
{
if (u<k(n+m) && u>=k(n))
return Recursive_BSpline(n,m,u);
else if (u==BB && n+m==knot_number-1)
return Recursive_BSpline(n,m,u);
else
return 0.0;
}
double knot_partition::Recursive_BSpline(int n,int d,double u)
{
double divisor1,divisor2;
if (d==1) {
if (u>=k(n) && u<k(n+1))
return 1.0;
else if (n==knot_number-m-1 && u==BB)
return 1.0;
else
return 0.0;
}
else {
if (k(n)<k(n+d)) {
divisor1=k(n+d-1)-k(n);
divisor2=k(n+d)-k(n+1);
if (divisor1!=0.0 && divisor2!=0.0)
return ((u-k(n))/divisor1)*Recursive_BSpline(n,d-1,u)+
((k(n+d)-u)/divisor2)*Recursive_BSpline(n+1,d-1,u);
else if (divisor1!=0.0 && divisor2==0.0)
return ((u-k(n))/divisor1)*Recursive_BSpline(n,d-1,u);
else if (divisor1==0.0 && divisor2!=0.0)
return ((k(n+d)-u)/divisor2)*Recursive_BSpline(n+1,d-1,u);
else
return 0.0;
}
else
return 0.0;
}
}
double knot_partition::derived_BSpline(int n,int d,double u)
{
double d1,d2;
d1=k(n+d-1)-k(n);
d2=k(d+n)-k(n+1);
if (d1==0.0) {
if (d2==0.0)
return 0.0;
else
return -(d-1)*Recursive_BSpline(n+1,d-1,u)/d2;
}
else if (d2==0.0)
return (d-1)*Recursive_BSpline(n,d-1,u)/d1;
else
return (d-1)*(Recursive_BSpline(n,d-1,u)/d1-
Recursive_BSpline(n+1,d-1,u)/d2);
}
double knot_partition::derived2_BSpline(int n,int d,double u)
{
double d1,d2;
d1=k(n+d-1)-k(n);
d2=k(d+n)-k(n+1);
if (d1==0.0) {
if (d2==0.0)
return 0.0;
else
return -(d-1)*derived_BSpline(n+1,d-1,u)/d2;
}
else if (d2==0.0)
return (m-1)*derived_BSpline(n,d-1,u)/d1;
else
return (m-1)*(derived_BSpline(n,d-1,u)/d1-
derived_BSpline(n+1,d-1,u)/d2);
}
// File knot_par.h
#ifndef NOINCLUDE
#include "spltype.h"
#include "err.h"
#include "tem/pair.tem"
#include "tem/list.tem"
#include "tem/matvec.tem"
#endif
class knot_partition {
protected:
int m; /* Spline degree */
int knot_number;
int partition_type,more_knots_type;
int range_number;
int first_k; /* First k zero value */
vector<double> k; /* List of knots */
public:
knot_partition(int,int,int,int);
knot_partition(int,vector<double>&);
~knot_partition();
int rn();
void range(double,double *); /* Restituisce l'intervallo nodale di appartenenza */
/* void knot_insertion(double);
void knot_removal(double); */
int get_degree();
int get_knot_number();
double get_knot_value(int);
int get_knot_molt(double); /* It return the knot molteplicity */
double BSpline(int,double);
double derived_BSpline(int,int,double);
double derived2_BSpline(int,int,double);
private:
double Recursive_BSpline(int,int,double);
};
#define AA (double) 0.0
#define BB (double) 1.0
//pair.tem
// Template per gestire le molteplicita' dei nodi o dei c.p.
#include <ostream>
using namespace std;
template <class T,class D> class pair {
T fir;
D sec;
public:
pair();
pair(T,D);
~pair();
T get_first_data();
D get_second_data();
void set_first_data(T);
void set_second_data(D);
friend ostream& operator<< <>(ostream&,pair<T,D>);
friend ostream& operator<< <>(ostream&,pair<T,D>*);
friend istream& operator>> <>(istream&,pair<T,D>&);
pair<T,D>& operator=(pair<T,D>&);
//pair<T,D>& operator=(pair<T,D>);
bool operator==(pair<T,D>&);
bool operator!=(const pair<T,D>&);
//bool operator==(pair<T,D>);
//bool operator!=(pair<T,D>);
bool operator>(const pair<T,D>&); // Gli operatori di confronto
bool operator<(const pair<T,D>&); // sono stati inseriti per
bool operator>=(const pair<T,D>&); // ragioni di esportabilita'
bool operator<=(const pair<T,D>&); // del codice
pair<T,D>& operator=(const int);
};
// Template implementation
template <class T,class D> pair<T,D>::pair()
{
fir=0;
sec=0;
}
template <class T,class D> pair<T,D>::pair(T d,D oc)
{
fir=d;
sec=oc;
}
template <class T,class D> pair<T,D>::~pair()
{
}
template <class T,class D> T pair<T,D>::get_first_data()
{
return fir;
}
template <class T,class D> D pair<T,D>::get_second_data()
{
return sec;
}
template <class T,class D> void pair<T,D>::set_first_data(T oc)
{
fir=oc;
}
template <class T,class D> void pair<T,D>::set_second_data(D d)
{
sec=d;
}
template <class T,class D> ostream& operator<<(ostream &stream,pair<T,D> p)
{
stream << p.get_first_data() << "\t" << p.get_second_data() <<" ";
return stream;
}
template <class T,class D> ostream& operator<<(ostream &stream,pair<T,D> *p)
{
stream << p.get_first_data() << "\t" << p.get_second_data() << " ";
return stream;
}
template <class T,class D> istream& operator>>(istream &stream,pair<T,D> &p)
{
stream >> p.fir;
stream >> p.las;
return stream;
}
template <class T,class D> pair<T,D>& pair<T,D>::operator=(const int d)
{
fir=0;
sec=0;
return *this;
}
template <class T,class D> bool pair<T,D>::operator==(pair<T,D>& p)
{
if (fir==p.get_first_data() && sec==p.get_second_data())
return true;
else
return false;
}
template <class T,class D> bool pair<T,D>::operator!=(const pair<T,D>& p)
{
return !(this==p);
}
/*template <class T,class D> bool pair<T,D>::operator==(pair<T,D> p)
{
if (fir==p.get_first_data() && sec==p.get_second_data())
return true;
else
return false;
}
template <class T,class D> bool pair<T,D>::operator!=(pair<T,D> p)
{
return !(this==p);
}*/
template <class T,class D> pair<T,D>& pair<T,D>::operator=(pair<T,D>& p)
{
fir=p.get_first_data();
sec=p.get_second_data();
return *this;
}
/*template <class T,class D> pair<T,D>& pair<T,D>::operator=(pair<T,D> p)
{
fir=p.get_first_data();
sec=p.get_second_data();
return *this;
}*/
template <class T,class D> bool pair<T,D>::operator<(const pair<T,D>& p)
{
return true;
}
template <class T,class D> bool pair<T,D>::operator>(const pair<T,D>& p)
{
return true;
}
template <class T,class D> bool pair<T,D>::operator<=(const pair<T,D>& p)
{
return true;
}
template <class T,class D> bool pair<T,D>::operator>=(const pair<T,D>& p)
{
return true;
}
Evito di postarvi anche gli altri 2 template (se vi servono li metto)...già solo in pair.tem ho questo:
g++ -c -Wno-deprecated knot_par.cpp
In file included from knot_par.h:6,
from knot_par.cpp:6:
tem/pair.tem:37: error: expected constructor, destructor, or type conversion before ‘<’ token
tem/pair.tem:43: error: expected constructor, destructor, or type conversion before ‘<’ token
tem/pair.tem:49: error: expected constructor, destructor, or type conversion before ‘<’ token
tem/pair.tem:53: error: expected initializer before ‘<’ token
tem/pair.tem:58: error: expected initializer before ‘<’ token
tem/pair.tem:64: error: expected initializer before ‘<’ token
tem/pair.tem:69: error: expected initializer before ‘<’ token
tem/pair.tem:74: error: reference to ‘pair’ is ambiguous
tem/pair.tem:7: error: candidates are: template<class T, class D> class pair
/usr/include/c++/4.4/bits/stl_pair.h:67: error: template<class _T1, class _T2> struct std::pair
tem/pair.tem:74: error: ‘pair’ has not been declared
tem/pair.tem:74: error: expected ‘,’ or ‘...’ before ‘<’ token
tem/pair.tem: In function ‘std::ostream& operator<<(std::ostream&, int)’:
tem/pair.tem:76: error: ‘p’ was not declared in this scope
tem/pair.tem: At global scope:
tem/pair.tem:80: error: reference to ‘pair’ is ambiguous
tem/pair.tem:7: error: candidates are: template<class T, class D> class pair
/usr/include/c++/4.4/bits/stl_pair.h:67: error: template<class _T1, class _T2> struct std::pair
tem/pair.tem:80: error: ‘pair’ has not been declared
tem/pair.tem:80: error: expected ‘,’ or ‘...’ before ‘<’ token
tem/pair.tem:80: error: redefinition of ‘template<class T, class D> std::ostream& operator<<(std::ostream&, int)’
tem/pair.tem:74: error: ‘template<class T, class D> std::ostream& operator<<(std::ostream&, int)’ previously declared here
tem/pair.tem: In function ‘std::ostream& operator<<(std::ostream&, int)’:
tem/pair.tem:82: error: ‘p’ was not declared in this scope
tem/pair.tem: At global scope:
tem/pair.tem:86: error: reference to ‘pair’ is ambiguous
tem/pair.tem:7: error: candidates are: template<class T, class D> class pair
/usr/include/c++/4.4/bits/stl_pair.h:67: error: template<class _T1, class _T2> struct std::pair
tem/pair.tem:86: error: ‘pair’ has not been declared
tem/pair.tem:86: error: expected ‘,’ or ‘...’ before ‘<’ token
tem/pair.tem: In function ‘std::istream& operator>>(std::istream&, int)’:
tem/pair.tem:88: error: ‘p’ was not declared in this scope
tem/pair.tem: At global scope:
tem/pair.tem:93: error: expected constructor, destructor, or type conversion before ‘<’ token
tem/pair.tem error: expected initializer before ‘<’ token
tem/pair.tem:108: error: expected initializer before ‘<’ token
tem/pair.tem:126: error: expected constructor, destructor, or type conversion before ‘<’ token
tem/pair.tem:140: error: expected initializer before ‘<’ token
tem/pair.tem:145: error: expected initializer before ‘<’ token
tem/pair.tem:150: error: expected initializer before ‘<’ token
tem/pair.tem:155: error: expected initializer before ‘<’ token
Qualcuno riesce a darmi una mano? Se necessario posso postare anche i 2 template inclusi che mancano o tutto il progetto...
Grazie in anticipo !
Stefano